共用方式為


ExpansionProvider.GetExpansionFunction Method

Definition

Returns an ExpansionFunction object based on the contents of a particular node in the XML template file for the snippet.

Overloads

GetExpansionFunction(XmlElement, String)

Returns an IVsExpansionFunction object representing the expansion function described in the given XML template node.

GetExpansionFunction(IXMLDOMNode, String, IVsExpansionFunction)

Returns a IVsExpansionFunction object representing the expansion function described in the given XML template node (COM implementation).

Remarks

An expansion function is associated with a substitution variable (also known as a field) in a template. Whenever that variable is substituted in the template, the expansion function is invoked to provide a value for the substitution. The expansion function is defined as a name that takes zero or more parameters. This name is associated with an actual code function that does the work required to produce the value. The IXMLDOMNode parses the expansion function and creates an ExpansionFunction object that returns the required values. This ExpansionFunction object is then called upon to return the appropriate value for the variable each time the variable is substituted in the template.

GetExpansionFunction(XmlElement, String)

Returns an IVsExpansionFunction object representing the expansion function described in the given XML template node.

public:
 virtual Microsoft::VisualStudio::TextManager::Interop::IVsExpansionFunction ^ GetExpansionFunction(System::Xml::XmlElement ^ xmlFunctionNode, System::String ^ fieldName);
public virtual Microsoft.VisualStudio.TextManager.Interop.IVsExpansionFunction GetExpansionFunction (System.Xml.XmlElement xmlFunctionNode, string fieldName);
abstract member GetExpansionFunction : System.Xml.XmlElement * string -> Microsoft.VisualStudio.TextManager.Interop.IVsExpansionFunction
override this.GetExpansionFunction : System.Xml.XmlElement * string -> Microsoft.VisualStudio.TextManager.Interop.IVsExpansionFunction
Public Overridable Function GetExpansionFunction (xmlFunctionNode As XmlElement, fieldName As String) As IVsExpansionFunction

Parameters

xmlFunctionNode
XmlElement

[in] An XmlElement object representing the expansion function definition.

fieldName
String

[in] The name of the variable or field this expansion function represents.

Returns

If successful, returns an IVsExpansionFunction object; otherwise, returns a null value indicating no expansion function was found in the specified XML node.

Remarks

This method is called from Visual Studio while parsing a code snippet template file.

The base method parses any arguments from the text contained in the expansion function XML template node and then calls the CreateExpansionFunction method in the LanguageService class to create an ExpansionFunction object. The field name and argument list are set in the ExpansionFunction object and the object is returned as an IVsExpansionFunction object. If there was any problem parsing the expansion function, the base method returns null. The base method assumes the expansion function is defined according to the code snippet schema (as described specifically in the Function Element (Intellisense Code Snippets) reference).

Applies to

GetExpansionFunction(IXMLDOMNode, String, IVsExpansionFunction)

Returns a IVsExpansionFunction object representing the expansion function described in the given XML template node (COM implementation).

public:
 virtual int GetExpansionFunction(MSXML::IXMLDOMNode ^ xmlFunctionNode, System::String ^ fieldName, [Runtime::InteropServices::Out] Microsoft::VisualStudio::TextManager::Interop::IVsExpansionFunction ^ % func);
public:
 virtual int GetExpansionFunction(MSXML::IXMLDOMNode ^ xmlFunctionNode, Platform::String ^ fieldName, [Runtime::InteropServices::Out] Microsoft::VisualStudio::TextManager::Interop::IVsExpansionFunction ^ &  func);
 virtual int GetExpansionFunction(MSXML::IXMLDOMNode const & xmlFunctionNode, std::wstring const & fieldName, [Runtime::InteropServices::Out] Microsoft::VisualStudio::TextManager::Interop::IVsExpansionFunction const & & func);
public virtual int GetExpansionFunction (MSXML.IXMLDOMNode xmlFunctionNode, string fieldName, out Microsoft.VisualStudio.TextManager.Interop.IVsExpansionFunction func);
abstract member GetExpansionFunction : MSXML.IXMLDOMNode * string * IVsExpansionFunction -> int
override this.GetExpansionFunction : MSXML.IXMLDOMNode * string * IVsExpansionFunction -> int
Public Overridable Function GetExpansionFunction (xmlFunctionNode As IXMLDOMNode, fieldName As String, ByRef func As IVsExpansionFunction) As Integer

Parameters

xmlFunctionNode
IXMLDOMNode

[in] A IXMLDOMNode object representing the expansion function description.

fieldName
String

[in] The name of the variable or field this expansion function represents.

func
IVsExpansionFunction

[out] Returns an IVsExpansionFunction object representing the implementation of the expansion function.

Returns

If successful, returns S_OK; otherwise, returns an error code.

Implements

Examples

Here is how the managed package framework implements this GetExpansionFunction method. This example shows how to convert an IXMLDOMNode object into an XmlElement object in C#.

using Microsoft.VisualStudio.TextManager.Interop;  
using Microsoft.VisualStudio.OLE.Interop;  
using System.Xml;  
using System;  

namespace Microsoft.VisualStudio.Package  
{  
    [CLSCompliant(false)]  
    [System.Runtime.InteropServices.ComVisible(true)]  
    public class ExpansionProvider : IDisposable, IVsExpansionClient  
    {  
        public virtual int GetExpansionFunction(  
                    MSXML.IXMLDOMNode xmlFunctionNode,  
                    string fieldName,  
                out IVsExpansionFunction func)  
        {  
            XmlDocument doc = new XmlDocument();  
            doc.LoadXml(xmlFunctionNode.xml);  
            func = GetExpansionFunction(doc.DocumentElement, fieldName);  
            return VsConstants.S_OK;  
        }  
    }  
}  

Remarks

This method is an implementation of the GetExpansionFunction method on the IVsExpansionClient interface.

The base method converts the IXMLDOMNode object into an XmlElement object and calls the other GetExpansionFunction method.

Applies to