共用方式為


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.10.0 (in Microsoft.VisualStudio.Package.LanguageService.10.0.dll)
  Microsoft.VisualStudio.Package.LanguageService.11.0 (in Microsoft.VisualStudio.Package.LanguageService.11.0.dll)
  Microsoft.VisualStudio.Package.LanguageService (in Microsoft.VisualStudio.Package.LanguageService.dll)

Syntax

'宣告
Public Overridable Function CreateExpansionFunction ( _
    provider As ExpansionProvider, _
    functionName As String _
) As ExpansionFunction
public virtual ExpansionFunction CreateExpansionFunction(
    ExpansionProvider provider,
    string functionName
)

Parameters

Return Value

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

Remarks

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.

Examples

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;
        }
    }
}

.NET Framework Security

See Also

Reference

LanguageService Class

Microsoft.VisualStudio.Package Namespace

ExpansionFunction