Share via


CodeClass2.AddProperty 方法 (String, String, Object, Object, vsCMAccess, Object)

在類別中建立新屬性建構。

命名空間:  EnvDTE80
組件:  EnvDTE80 (在 EnvDTE80.dll 中)

語法

'宣告
Function AddProperty ( _
    GetterName As String, _
    PutterName As String, _
    Type As Object, _
    Position As Object, _
    Access As vsCMAccess, _
    Location As Object _
) As CodeProperty
CodeProperty AddProperty(
    string GetterName,
    string PutterName,
    Object Type,
    Object Position,
    vsCMAccess Access,
    Object Location
)
CodeProperty^ AddProperty(
    String^ GetterName, 
    String^ PutterName, 
    Object^ Type, 
    Object^ Position, 
    vsCMAccess Access, 
    Object^ Location
)
abstract AddProperty : 
        GetterName:string * 
        PutterName:string * 
        Type:Object * 
        Position:Object * 
        Access:vsCMAccess * 
        Location:Object -> CodeProperty 
function AddProperty(
    GetterName : String, 
    PutterName : String, 
    Type : Object, 
    Position : Object, 
    Access : vsCMAccess, 
    Location : Object
) : CodeProperty

參數

  • GetterName
    型別:System.String
    必要項。取得該屬性值的函式名稱。
  • PutterName
    型別:System.String
    必要項。設定該屬性的函式名稱。
  • Position
    型別:System.Object
    選擇項。預設 = 0。其後要加入新項目的程式碼項目。
    如果這個值是長整數資料型別,那麼 Position 方法會指出其後要加入新項目的項目。
    由於集合是從 1 開始計算,傳遞 0 表示新的項目必須放在集合起始的位置。值為 -1 時表示這個項目必須放在集合結尾的位置。
  • Location
    型別:System.Object
    選擇項。新函式的位置。

傳回值

型別:EnvDTE.CodeProperty
CodeProperty 物件。

實作

CodeClass.AddProperty(String, String, Object, Object, vsCMAccess, Object)

備註

原生 Visual C++ 的完整型別名稱必須使用冒號 (::) 分隔。 其他所有語言都支援句號分隔的格式。

引數的正確性取決於程式碼模型後的程式語言。

注意事項注意事項

在特定類型的編輯之後,程式碼模型項目 (例如類別、結構、函式、屬性、委派等) 的值可能不具決定性,表示其值不一定維持相同。 如需詳細資訊,請參閱使用程式碼模型探索程式碼 (Visual Basic) 的<程式碼模型項目值可以變更>一節。

範例

[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);
    }
}

.NET Framework 安全性

請參閱

參考

CodeClass2 介面

AddProperty 多載

EnvDTE80 命名空間

其他資源

HOW TO:編譯和執行 Automation 物件模型程式碼範例

使用程式碼模型探索程式碼 (Visual Basic)

使用程式碼模型探索程式碼 (Visual C#)