CodeSnippetTypeMember CodeSnippetTypeMember CodeSnippetTypeMember CodeSnippetTypeMember Class


Represents a member of a type using a literal code fragment.

public ref class CodeSnippetTypeMember : System::CodeDom::CodeTypeMember
public class CodeSnippetTypeMember : System.CodeDom.CodeTypeMember
type CodeSnippetTypeMember = class
    inherit CodeTypeMember
Public Class CodeSnippetTypeMember
Inherits CodeTypeMember


The following example demonstrates the use of the CodeSnippetTypeMember class to store literal code in a string format. 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());
    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 'GenCodeFromMember
End Class 'Program 


CodeSnippetTypeMember can represent a member of a type using a literal code fragment that is included directly in the source without modification. This code can be included in the type declaration.

A CodeSnippetTypeMember stores a section of code, exactly in its original format, as a string. The CodeDOM does not translate literal code fragments. Literal code fragments are stored and output in their original format. CodeDOM objects that contain literal code are provided so developers can encapsulate code that is already in the target language.

The Text property contains the literal code for the type member.


CodeSnippetTypeMember() CodeSnippetTypeMember() CodeSnippetTypeMember() CodeSnippetTypeMember()

Initializes a new instance of the CodeSnippetTypeMember class.

CodeSnippetTypeMember(String) CodeSnippetTypeMember(String) CodeSnippetTypeMember(String) CodeSnippetTypeMember(String)

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


Attributes Attributes Attributes Attributes

Gets or sets the attributes of the member.

(Inherited from CodeTypeMember)
Comments Comments Comments Comments

Gets the collection of comments for the type member.

(Inherited from CodeTypeMember)
CustomAttributes CustomAttributes CustomAttributes CustomAttributes

Gets or sets the custom attributes of the member.

(Inherited from CodeTypeMember)
EndDirectives EndDirectives EndDirectives EndDirectives

Gets the end directives for the member.

(Inherited from CodeTypeMember)
LinePragma LinePragma LinePragma LinePragma

Gets or sets the line on which the type member statement occurs.

(Inherited from CodeTypeMember)
Name Name Name Name

Gets or sets the name of the member.

(Inherited from CodeTypeMember)
StartDirectives StartDirectives StartDirectives StartDirectives

Gets the start directives for the member.

(Inherited from CodeTypeMember)
Text Text Text Text

Gets or sets the literal code fragment for the type member.

UserData UserData UserData UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)


Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to