CodeSnippetTypeMember 构造函数

定义

初始化 CodeSnippetTypeMember 类的新实例。

重载

CodeSnippetTypeMember()

初始化 CodeSnippetTypeMember 类的新实例。

CodeSnippetTypeMember(String)

使用指定的文本初始化 CodeSnippetTypeMember 类的新实例。

CodeSnippetTypeMember()

初始化 CodeSnippetTypeMember 类的新实例。

public:
 CodeSnippetTypeMember();
public CodeSnippetTypeMember ();
Public Sub New ()

适用于

CodeSnippetTypeMember(String)

使用指定的文本初始化 CodeSnippetTypeMember 类的新实例。

public:
 CodeSnippetTypeMember(System::String ^ text);
public CodeSnippetTypeMember (string text);
new System.CodeDom.CodeSnippetTypeMember : string -> System.CodeDom.CodeSnippetTypeMember
Public Sub New (text As String)

参数

text
String

类型成员的代码片段。

示例

下面的示例演示如何使用 CodeSnippetTypeMember 构造函数创建类的 CodeSnippetTypeMember 实例。 此代码示例是为 GenerateCodeFromMember 该方法提供的大型示例的一部分。

static void GenCodeFromMember(CodeDomProvider provider, CodeGeneratorOptions options)
{
    options.BracingStyle = "C";
    CodeMemberMethod method1 = new CodeMemberMethod();
    method1.Name = "ReturnString";
    method1.Attributes = MemberAttributes.Public;
    method1.ReturnType = new CodeTypeReference("System.String");
    method1.Parameters.Add(new CodeParameterDeclarationExpression("System.String", "text"));
    method1.Statements.Add(new CodeMethodReturnStatement(new CodeArgumentReferenceExpression("text")));
    StringWriter sw = new StringWriter();
    provider.GenerateCodeFromMember(method1, sw, options);
    snippetMethod = new CodeSnippetTypeMember(sw.ToString());
}
    Shared Sub GenCodeFromMember(ByVal provider As CodeDomProvider, ByVal options As CodeGeneratorOptions) 
        options.BracingStyle = "C"
        Dim method1 As New CodeMemberMethod()
        method1.Name = "ReturnString"
        method1.Attributes = MemberAttributes.Public
        method1.ReturnType = New CodeTypeReference("System.String")
        method1.Parameters.Add(New CodeParameterDeclarationExpression("System.String", "text"))
        method1.Statements.Add(New CodeMethodReturnStatement(New CodeArgumentReferenceExpression("text")))
        Dim sw As New StringWriter()
        provider.GenerateCodeFromMember(method1, sw, options)
        snippetMethod = New CodeSnippetTypeMember(sw.ToString())
    
    End Sub
End Class

适用于