ReplaceTokens Class

Summary

Replaces tokens in the original input with user-supplied values.
Assembly
NAnt.Core.dll
Namespace
NAnt.Core.Filters
Interfaces
  • IDisposable
Base Types
graph BT Type-->Base0["Filter"] click Base0 "/api/NAnt.Core.Filters/Filter" Base0-->Base1["ChainableReader"] click Base1 "/api/NAnt.Core.Filters/ChainableReader" Base1-->Base2["Element"] click Base2 "/api/NAnt.Core/Element" Base2-->Base3["Object"] Type-.->Interface0["IDisposable"] Type["ReplaceTokens"] class Type type-node

Syntax

[ElementName("replacetokens")]
public class ReplaceTokens : Filter, IDisposable

Examples

Replace all occurrences of the string @DATE@ with the value of property "TODAY".

    <replacetokens>
    <token key="DATE" value="${TODAY}" />
</replacetokens>

Replace all occurrences of the string <DATE> with the value of property "TODAY".

    <replacetokens begintoken="&lt;" endtoken="&gt;">
    <token key="DATE" value="${TODAY}" />
</replacetokens>

Remarks

This filter replaces all token surrounded by a beginning and ending token. The default beginning and ending tokens both default to '@'. The optional NAnt.Core.Filters.ReplaceTokens.BeginToken and NAnt.Core.Filters.ReplaceTokens.EndToken attributes can be specified to change either token. By default string comparisons are case sensitive but this can be changed by setting the optional NAnt.Core.Filters.ReplaceTokens.IgnoreCase attribute to true.

Tokens are specified by using the NAnt.Core.Types.Token element. It is possible to specify from 1 to n tokens and replacement values. Values can be any valid NAnt expression.

Filters are intended to be used as a element of a NAnt.Core.Filters.FilterChain.

Attributes

Type Description
ElementNameAttribute Indicates that class should be treated as a NAnt element.

Properties

Name Value Summary
Base bool
Gets a value indicating if the reader is backed by a stream in the chain.
Inherited from ChainableReader
BeginToken char
Marks the beginning of a token. The default is "@".
CustomXmlProcessing bool
Gets a value indicating whether the element is performing additional processing using the NAnt.Core.Element.XmlNode that was used to initialize the element.
Inherited from Element
EndToken char
Marks the end of a token. The default is "@".
IfDefined bool
If true then the filter will be used; otherwise, skipped. The default is true.
Inherited from Filter
IgnoreCase bool
Determines if case will be ignored. The default is false.
Location Location
Gets or sets the location in the build file where the element is defined.
Inherited from Element
Name string
Gets the name of the XML element used to initialize this element.
Inherited from Element
NamespaceManager XmlNamespaceManager
Gets or sets the System.Xml.XmlNamespaceManager.
Inherited from Element
Parent Object
Gets or sets the parent of the element.
Inherited from Element
Project Project
Gets or sets the NAnt.Core.Element.Project to which this element belongs.
Inherited from Element
Properties PropertyDictionary
Gets the properties local to this NAnt.Core.Element and the NAnt.Core.Element.Project.
Inherited from Element
Tokens Token[]
Tokens and replacement values.
UnlessDefined bool
Opposite of NAnt.Core.Filters.Filter.IfDefined. If false then the filter will be executed; otherwise, skipped. The default is false.
Inherited from Filter
XmlNode XmlNode
Gets or sets the XML node of the element.
Inherited from Element

Methods

Name Value Summary
Chain(ChainableReader) void
Construct that allows this filter to be chained to the one in the parameter chainedReader.
Chain(TextReader) void
Makes it so all calls to Read and Peek are passed the TextReader passed as a parameter.
Inherited from ChainableReader
Close() void
Closes the reader.
Inherited from ChainableReader
CopyTo(Element) void
Copies all instance data of the NAnt.Core.Element to a given NAnt.Core.Element.
Inherited from Element
Dispose() void
Calls close and suppresses the finalizer for the object.
Inherited from ChainableReader
GetAttributeConfigurationNode(FrameworkInfo, string) XmlNode
Locates the XML node for the specified attribute in the project configuration node.
Inherited from Element
GetAttributeConfigurationNode(XmlNode, FrameworkInfo, string) XmlNode
Inherited from Element
GetLocation() Location
Retrieves the location in the build file where the element is defined.
Inherited from Element
Initialize() void
Initialize the filter by setting its parameters.
Initialize(XmlNode) void
Performs default initialization.
Inherited from Element
InitializeBuildElement(Element, XmlNode, Element, Type) Element
Initializes the build element.
Inherited from Element
static
InitializeElement(XmlNode) void
Derived classes should override to this method to provide extra initialization and validation not covered by the base class.
Inherited from Element
InitializeFilter() void
Called after construction and after properties are set. Allows for filter initialization.
Inherited from Filter
InitializeXml(XmlNode, PropertyDictionary, FrameworkInfo) void
Initializes all build attributes and child elements.
Inherited from Element
Log(Level, string) void
Logs a message with the given priority.
Inherited from Element
Log(Level, string, Object[]) void
Logs a message with the given priority.
Inherited from Element
Peek() int
Reads the next character applying the filter logic without advancing the current position in the stream. Peek currently is not supported.
Read() int
Reads the next character applying the filter logic.