CodeSnippetTypeMember Constructor (String)


Initializes a new instance of the CodeSnippetTypeMember class using the specified text.

Namespace:   System.CodeDom
Assembly:  System (in System.dll)

public CodeSnippetTypeMember(
	string text


Type: System.String

The literal code fragment for the type member.

The following example demonstrates the use of the CodeSnippetTypeMember constructor to create an instance of the CodeSnippetTypeMember class. This code example is part of a larger example provided for the GenerateCodeFromMember method.

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());

.NET Framework
Available since 1.1
Return to top