Modifier

Partager via


CodeSnippetTypeMember Class

Definition

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

public ref class CodeSnippetTypeMember : System::CodeDom::CodeTypeMember
public class CodeSnippetTypeMember : System.CodeDom.CodeTypeMember
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Runtime.InteropServices.ComVisible(true)]
[System.Serializable]
public class CodeSnippetTypeMember : System.CodeDom.CodeTypeMember
type CodeSnippetTypeMember = class
    inherit CodeTypeMember
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)>]
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Serializable>]
type CodeSnippetTypeMember = class
    inherit CodeTypeMember
Public Class CodeSnippetTypeMember
Inherits CodeTypeMember
Inheritance
CodeSnippetTypeMember
Attributes

Examples

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
End Class

Remarks

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.

Constructors

CodeSnippetTypeMember()

Initializes a new instance of the CodeSnippetTypeMember class.

CodeSnippetTypeMember(String)

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

Properties

Attributes

Gets or sets the attributes of the member.

(Inherited from CodeTypeMember)
Comments

Gets the collection of comments for the type member.

(Inherited from CodeTypeMember)
CustomAttributes

Gets or sets the custom attributes of the member.

(Inherited from CodeTypeMember)
EndDirectives

Gets the end directives for the member.

(Inherited from CodeTypeMember)
LinePragma

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

(Inherited from CodeTypeMember)
Name

Gets or sets the name of the member.

(Inherited from CodeTypeMember)
StartDirectives

Gets the start directives for the member.

(Inherited from CodeTypeMember)
Text

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

UserData

Gets the user-definable data for the current object.

(Inherited from CodeObject)

Methods

Equals(Object)

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

(Inherited from Object)
GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
ToString()

Returns a string that represents the current object.

(Inherited from Object)

Applies to