CodeClass2.IsShared 屬性

取得或設定類別的共用 (靜態) 狀態。

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

語法

'宣告
Property IsShared As Boolean
    Get
    Set
bool IsShared { get; set; }
property bool IsShared {
    bool get ();
    void set (bool value);
}
abstract IsShared : bool with get, set
function get IsShared () : boolean
function set IsShared (value : boolean)

屬性值

型別:System.Boolean
如果類別為共用 (靜態) 則為 true,否則為 false。

注意事項注意事項

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

範例

[Visual Basic]

Sub IsSharedExample(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 CodeClass2 = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementClass), CodeClass2)

        ' Display whether or not the class is shared.
        If cls.IsShared Then
            MsgBox("Class is shared")
        Else
            MsgBox("Class is not shared")
        End If

    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub

[C#]

public void IsSharedExample(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;
        CodeClass2 cls = (CodeClass2) 
        sel.ActivePoint.get_CodeElement(vsCMElement.vsCMElementClass);

        // Display whether or not the class is shared.
        if (cls.IsShared)
        {
            MessageBox.Show("Class is shared");
        }
        else
        {
            MessageBox.Show("Class is not shared");
        }
    }
    catch(System.Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

請參閱

參考

CodeClass2 介面

EnvDTE80 命名空間

其他資源

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

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

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