CodeSnippetTypeMember 类

定义

使用原义代码片段表示类型成员。Represents a member of a type using a literal code fragment.

public ref class CodeSnippetTypeMember : System::CodeDom::CodeTypeMember
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.AutoDispatch)]
[System.Serializable]
public class CodeSnippetTypeMember : System.CodeDom.CodeTypeMember
type CodeSnippetTypeMember = class
    inherit CodeTypeMember
Public Class CodeSnippetTypeMember
Inherits CodeTypeMember
继承
CodeSnippetTypeMember
属性

示例

下面的示例演示如何使用CodeSnippetTypeMember类以字符串格式存储文本代码。The following example demonstrates the use of the CodeSnippetTypeMember class to store literal code in a string format. 此代码示例是为GenerateCodeFromMember方法提供的一个更大示例的一部分。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

注解

CodeSnippetTypeMember可以使用在不进行修改的情况下直接包含在源中的原义代码片段来表示类型的成员。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.

以字符串的形式存储代码的一部分,它的原始格式完全相同。CodeSnippetTypeMemberA CodeSnippetTypeMember stores a section of code, exactly in its original format, as a string. CodeDOM 不会转换原义代码片段。The CodeDOM does not translate literal code fragments. 原义代码片段以其原始格式存储和输出。Literal code fragments are stored and output in their original format. 提供了包含原义代码的 CodeDOM 对象, 以便开发人员可以封装目标语言中已经存在的代码。CodeDOM objects that contain literal code are provided so developers can encapsulate code that is already in the target language.

Text属性包含类型成员的文字代码。The Text property contains the literal code for the type member.

构造函数

CodeSnippetTypeMember()

初始化 CodeSnippetTypeMember 类的新实例。Initializes a new instance of the CodeSnippetTypeMember class.

CodeSnippetTypeMember(String)

使用指定的文本初始化 CodeSnippetTypeMember 类的新实例。Initializes a new instance of the CodeSnippetTypeMember class using the specified text.

属性

Attributes

获取或设置成员的特性。Gets or sets the attributes of the member.

(继承自 CodeTypeMember)
Comments

获取类型成员的注释集合。Gets the collection of comments for the type member.

(继承自 CodeTypeMember)
CustomAttributes

获取或设置成员的自定义特性。Gets or sets the custom attributes of the member.

(继承自 CodeTypeMember)
EndDirectives

获取成员的结束指令。Gets the end directives for the member.

(继承自 CodeTypeMember)
LinePragma

获取或设置类型成员语句所在的行。Gets or sets the line on which the type member statement occurs.

(继承自 CodeTypeMember)
Name

获取或设置成员名。Gets or sets the name of the member.

(继承自 CodeTypeMember)
StartDirectives

获取成员的开始指令。Gets the start directives for the member.

(继承自 CodeTypeMember)
Text

获取或设置类型成员的原义代码片段。Gets or sets the literal code fragment for the type member.

UserData

获取当前对象的用户可定义数据。Gets the user-definable data for the current object.

(继承自 CodeObject)

方法

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetHashCode()

作为默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回表示当前对象的字符串。Returns a string that represents the current object.

(继承自 Object)

适用于