Class TagExtensionMethod
- Namespace
- Dynamicweb.Rendering
- Assembly
- Dynamicweb.dll
Tag extension add-in for creating extension methods for template tags
public abstract class TagExtensionMethod
- Inheritance
-
TagExtensionMethod
- Inherited Members
Examples
using Dynamicweb.Core;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Rendering;
//AddInName is the name of the extension method - <!--@DwPageName.Substring(12)--> will give an AddInName of 'Substring'
[AddInName("Substring")]
public class TagExtensionMethodSample : TagExtensionMethod
{
public override string ExecuteMethod(string value)
{
//This is the entire string passed to the Substring method - everything between the ()
object fullPassedArgument = this.Argument;
//This method requires at least one argument
if (this.Arguments.Count > 0)
{
//First argument is the startIndex of the Substring method
int startIndex = Converter.ToInt32(this.Arguments[0]);
if (startIndex > value.Length - 1)
{
//Otherwise an exception would occur
return value;
}
if (this.Arguments.Count > 1)
{
//If the method is passed 2 arguments, we use the Substring overload that takes a length.
int length = Converter.ToInt32(this.Arguments[1]);
if (length > value.Length - 1)
{
//Otherwise an exception would occur
return value.Substring(startIndex);
}
else
{
return value.Substring(startIndex, length);
}
}
else
{
//There is only one argument, use the Substring method that applies.
return value.Substring(startIndex);
}
}
else
{
return value;
}
}
}
Properties
Argument
Gets the raw argument passed to the extension method.
public string Argument { get; }
Property Value
- string
- Entire string argument passed to the extension method in the (). I.e. the string 'argument' in SomeTag.MyMethod(argument).
Arguments
Gets the arguments parsed into a
Generic.List(Of Object)
with one entry for each argument seperated with comma.public List<object> Arguments { get; }
Property Value
- List<object>
- A
Generic.List(Of Object)
containing the values from the arguments. The values are not trimmed, so 'arg1, arg2' would create to items in list, 'arg1' and ' arg2'
MethodName
Gets the name of the tag that this instance of the method is applied to.
public string MethodName { get; }
Property Value
- string
- The name of the tag.
TagName
Gets the name of the tag that this instance of the method is applied to.
public string TagName { get; }
Property Value
- string
- The name of the tag.
Template
Gets the raw argument passed to the extension method.
public Template Template { get; }
Property Value
- Template
- Entire string argument passed to the extension method in the (). I.e. the string 'argument' in SomeTag.MyMethod(argument).
Methods
ExecuteMethod(string)
Override this method and return the modified string.
public virtual string ExecuteMethod(string value)
Parameters
value
string- The value of the template tag that the method is applied to.
Returns
- string
- Returns the string after it has been processed by the extension method.
Examples
using Dynamicweb.Core;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Rendering;
//AddInName is the name of the extension method - <!--@DwPageName.Substring(12)--> will give an AddInName of 'Substring'
[AddInName("Substring")]
public class TagExtensionMethodSample : TagExtensionMethod
{
public override string ExecuteMethod(string value)
{
//This is the entire string passed to the Substring method - everything between the ()
object fullPassedArgument = this.Argument;
//This method requires at least one argument
if (this.Arguments.Count > 0)
{
//First argument is the startIndex of the Substring method
int startIndex = Converter.ToInt32(this.Arguments[0]);
if (startIndex > value.Length - 1)
{
//Otherwise an exception would occur
return value;
}
if (this.Arguments.Count > 1)
{
//If the method is passed 2 arguments, we use the Substring overload that takes a length.
int length = Converter.ToInt32(this.Arguments[1]);
if (length > value.Length - 1)
{
//Otherwise an exception would occur
return value.Substring(startIndex);
}
else
{
return value.Substring(startIndex, length);
}
}
else
{
//There is only one argument, use the Substring method that applies.
return value.Substring(startIndex);
}
}
else
{
return value;
}
}
}
ParseArgumentsList(string)
protected static List<object> ParseArgumentsList(string arguments)
Parameters
arguments
string
Returns
ParseArgumentsObject(string)
protected static Dictionary<string, object> ParseArgumentsObject(string arguments)
Parameters
arguments
string