CodeClass2.AddProperty 方法

定义

在类中创建一个新的属性构造。

EnvDTE::CodeProperty AddProperty(std::wstring const & GetterName, std::wstring const & PutterName, winrt::Windows::Foundation::IInspectable const & Type, winrt::Windows::Foundation::IInspectable const & Position, EnvDTE::vsCMAccess Access = EnvDTE.vsCMAccess.vsCMAccessDefault, winrt::Windows::Foundation::IInspectable const & Location);
[System.Runtime.InteropServices.DispId(66)]
public EnvDTE.CodeProperty AddProperty (string GetterName, string PutterName, object Type, object Position, EnvDTE.vsCMAccess Access = EnvDTE.vsCMAccess.vsCMAccessDefault, object Location);
[<System.Runtime.InteropServices.DispId(66)>]
abstract member AddProperty : string * string * obj * obj * EnvDTE.vsCMAccess * obj -> EnvDTE.CodeProperty
Public Function AddProperty (GetterName As String, PutterName As String, Type As Object, Optional Position As Object, Optional Access As vsCMAccess = EnvDTE.vsCMAccess.vsCMAccessDefault, Optional Location As Object) As CodeProperty

参数

GetterName
String

必需。 获取该属性值的函数名称。

PutterName
String

必需。 设置属性的函数的名称。

Type
Object

必需。 属性的类型。 这可以是 CodeTypeRef 对象、 vsCMTypeRef 值或完全限定的类型名称。

Position
Object

可选。 默认值 = 0。 将在其后添加新元素的代码元素。

如果值为 Long 数据类型,则 Position 方法指示在其后添加新元素的元素。

因为集合从 1 开始计数,所以传递 0 指示应将新元素放置在集合的开始处。 值为 -1 表示应将元素放在结尾处。

Access
vsCMAccess

可选。 vsCMAccess指示访问类型的常量值。

Location
Object

可选。 新函数的位置。

返回

CodeProperty

CodeProperty 对象。

实现

属性

示例

[Visual Basic]

Sub AddPropertyExample(ByVal dte As DTE2)  
    ' Before running this example, open a code document from a project  
    ' and place the insertion point inside a class definition.  
    Try  
        ' Retrieve the CodeClass at the insertion point.  
        Dim sel As TextSelection = _  
            CType(dte.ActiveDocument.Selection, TextSelection)  
        Dim cls As CodeClass = _  
            CType(sel.ActivePoint.CodeElement( _  
            vsCMElement.vsCMElementClass), CodeClass)  

        ' Create a new member property.  
        cls.AddProperty("TestProperty", "TestProperty", _  
            vsCMTypeRef.vsCMTypeRefInt)  
    Catch ex As Exception  
        MsgBox(ex.Message)  
    End Try  
End Sub  

[C#]

public void AddPropertyExample(DTE2 dte)  
{  
    // Before running this example, open a code document from a project  
    // and place the insertion point inside a class definition.  
    try  
    {  
        // Retrieve the CodeClass at the insertion point.  
        TextSelection sel =   
            (TextSelection)dte.ActiveDocument.Selection;  
        CodeClass cls =   
            (CodeClass)sel.ActivePoint.get_CodeElement(  
            vsCMElement.vsCMElementClass);  

        // Create a new member property.  
        cls.AddProperty("TestProperty", "TestProperty",   
            vsCMTypeRef.vsCMTypeRefInt, -1,   
            vsCMAccess.vsCMAccessPublic, null);  
    }  
    catch (Exception ex)  
    {  
        MessageBox.Show(ex.Message);  
    }  
}  

注解

本机 Visual C++ 要求其完全限定类型名采用冒号分隔 (::) 格式。 所有其他语言支持句号分隔格式。

参数的正确性由代码模型后面的语言确定。

备注

在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。 有关详细信息,请参阅 "代码模型元素值在 使用代码模型查找代码时 可能发生变化" (Visual Basic) "。

适用于