Dynamicweb 8 Documentation
TagExtensionMethod Class
Members  Example 

Tag extension add-in for creating extension methods for template tags
Object Model
TagExtensionMethod ClassTemplate Class
Syntax
'Declaration
 
Public MustInherit Class TagExtensionMethod 
public abstract class TagExtensionMethod 
Example
How to inherit TagExtensionMethod and override ExecuteMethodHow to inherit TagExtensionMethod and override ExecuteMethod
using Dynamicweb;
using Dynamicweb.Rendering;
using Dynamicweb.Extensibility;

//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 = Input.FormatInteger(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 = Input.FormatInteger(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;
        }

    }

}
Imports Dynamicweb.Rendering
Imports Dynamicweb.Extensibility

'AddInName is the name of the extension method - <!--@DwPageName.Substring(12)--> will give an AddInName of 'Substring'
<AddInName("Substring")>
Public Class TagExtensionMethodSample
    Inherits TagExtensionMethod

    Public Overrides Function ExecuteMethod(value As String) As String
        'This is the entire string passed to the Substring method - everything between the ()
        Dim fullPassedArgument = Me.Argument

        'This method requires at least one argument
        If Me.Arguments.Count > 0 Then

            'First argument is the startIndex of the Substring method
            Dim startIndex As Integer = Input.FormatInteger(Me.Arguments(0))
            If startIndex > value.Length - 1 Then
                'Otherwise an exception would occur
                Return value
            End If

            If Me.Arguments.Count > 1 Then
                'If the method is passed 2 arguments, we use the Substring overload that takes a length.
                Dim length As Integer = Input.FormatInteger(Me.Arguments(1))
                If length > value.Length - 1 Then
                    'Otherwise an exception would occur
                    Return value.Substring(startIndex)
                Else
                    Return value.Substring(startIndex, length)
                End If
            Else
                'There is only one argument, use the Substring method that applies.
                Return value.Substring(startIndex)
            End If
        Else
            Return value
        End If

    End Function

End Class
Inheritance Hierarchy

System.Object
   Dynamicweb.Rendering.TagExtensionMethod

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

TagExtensionMethod Members
Dynamicweb.Rendering Namespace

Send Feedback