Condividi tramite


LanguageService.CreateExpansionFunction(ExpansionProvider, String) Method

Definition

Instantiates an ExpansionFunction class.

public:
 virtual Microsoft::VisualStudio::Package::ExpansionFunction ^ CreateExpansionFunction(Microsoft::VisualStudio::Package::ExpansionProvider ^ provider, System::String ^ functionName);
public virtual Microsoft.VisualStudio.Package.ExpansionFunction CreateExpansionFunction (Microsoft.VisualStudio.Package.ExpansionProvider provider, string functionName);
abstract member CreateExpansionFunction : Microsoft.VisualStudio.Package.ExpansionProvider * string -> Microsoft.VisualStudio.Package.ExpansionFunction
override this.CreateExpansionFunction : Microsoft.VisualStudio.Package.ExpansionProvider * string -> Microsoft.VisualStudio.Package.ExpansionFunction
Public Overridable Function CreateExpansionFunction (provider As ExpansionProvider, functionName As String) As ExpansionFunction

Parameters

provider
ExpansionProvider

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

functionName
String

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

Returns

If successful, returns an ExpansionFunction object; otherwise, returns a null value.

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

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.

Applies to