StringTemplate ClassNReco.Data Class Library Documentation
Conditional string template parser.
Inheritance Hierarchy

System Object
  NReco.Data StringTemplate

Namespace: NReco.Data
Assembly: NReco.Data (in NReco.Data.dll) Version: 1.0.2
Syntax

public class StringTemplate

The StringTemplate type exposes the following members.

Constructors

  NameDescription
Public methodStringTemplate(String)
Initializes a new instance of the StringTemplate class
Public methodStringTemplate(String, Int32)
Initializes a new instance of the StringTemplate class
Top
Methods

  NameDescription
Public methodEquals
Determines whether the specified Object is equal to the current Object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodFormatTemplate(IDictionary String, Object )
Replaces the format items in a specified string with the string representations of corresponding objects in a specified dictionary.
Public methodFormatTemplate(Func String, StringTemplate TokenResult )
Replaces the format items in a specified string with the string representations of corresponding objects returned by value handler.
Public methodGetHashCode
Serves as a hash function for a particular type.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Protected methodReadFormatOptions
Protected methodReadName
Protected methodReplaceTokens
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Fields

  NameDescription
Protected fieldExtraNameChars
Protected fieldTemplate
Top
Properties

  NameDescription
Public propertyRecursionLevel
Get or set max recursion level of token replacement (for cases when token value contains token definitions).
Public propertyReplaceMissedTokens
Get or set flag that determines replacement behaviour when token is not defined (true by default)
Top
Remarks

StringTemplate replaces all tokens started with '@' (token name should have only aphanumeric or '_-' chars). Token processing can be avoided by specifying @@ before any alphanumeric charachter, for example: (result: ). Special symbols used for formatting syntax ('@',']',';') can be escaped in the following way: \] or ]] (] symbol)\; or ;; (; symbol)
Examples

var strTpl = new StringTemplate("@Name[Hello, {0}; Hi all]!");
Console.Write( strTpl.FormatTemplate( new Dictionary<string,object>() { {"Name", "John"} } ) );  // Hi, John!
Console.Write( strTpl.FormatTemplate( new Dictionary<string,object>() ) );  // Hi, all!
See Also