Export (0) Print
Expand All
Expand Minimize

LanguageService.CreateExpansionFunction Method

Instantiates an ExpansionFunction class.

Namespace:  Microsoft.VisualStudio.Package
Assemblies:   Microsoft.VisualStudio.Package.LanguageService.9.0 (in Microsoft.VisualStudio.Package.LanguageService.9.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)
  Microsoft.VisualStudio.Package.LanguageService.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.12.0 (in Microsoft.VisualStudio.Package.LanguageService.12.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)

public virtual ExpansionFunction CreateExpansionFunction(
	ExpansionProvider provider,
	string functionName
)

Parameters

provider
Type: Microsoft.VisualStudio.Package.ExpansionProvider

[in] The ExpansionProvider that is to use the ExpansionFunction.

functionName
Type: System.String

[in] The name of the function the ExpansionFunction represents.

Return Value

Type: Microsoft.VisualStudio.Package.ExpansionFunction
If successful, returns an ExpansionFunction object; otherwise, returns a null value.

An expansion function presents a function embedded in a code snippet template that is to be called to provide one or more values as the template is expanded. If you are going to support expansion functions in your language's code snippets, you must derive a class from ExpansionFunction and return an instance of that class from this method.

The base method returns a null value, indicating that expansion functions are not supported by default.

This example shows one possible implementation of the CreateExpansionFunction method. The two expansion functions are implemented in two separate classes, MyClassNameExpansionFunction and MyEnumAccessTypeExpansionFunction. See the ExpansionFunction class for a more detailed version of this example.

using Microsoft.VisualStudio.Package;

namespace MyLanguagePackage
{
    public class MyLanguageService : LanguageService
    {
        public override ExpansionFunction CreateExpansionFunction(ExpansionProvider provider,
                                                                  string functionName)
        {
            ExpansionFunction function = null;
            if (String.Compare(functionName, "GetClassName", true) == 0)
            {
                function = new MyGetClassNameExpansionFunction(provider);
            }
            else if (String.Compare(functionName, "EnumAccessType", true) == 0)
            {
                function = new MyEnumAccessTypeExpansionFunction(provider);
            }
            return function;
        }
    }
}

Show:
© 2014 Microsoft