共用方式為


CodeFunction.IsShared 屬性

設定或取得是否已經靜態定義該項目,也就是該項目是否通用於此物件型別的所有執行個體,或是只適用於此物件。

命名空間:  EnvDTE
組件:  EnvDTE (在 EnvDTE.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。

備註

IsShared 會傳回或設定該方法是否與某一類別或某一類別的執行個體有關聯。 請注意,設定這個可能會產生語言相關的錯誤。 雖然 IsShared 成功傳回,但並不表示所產生的程式碼變更編譯成功。

注意事項注意事項

在特定類型的編輯之後,程式碼模型項目 (例如類別、結構、函式、屬性、委派等) 的值可能不具決定性,表示其值不一定維持相同。 如需詳細資訊,請參閱使用程式碼模型探索程式碼 (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 function.
    Try
        ' Retrieve the CodeFunction at the insertion point.
        Dim sel As TextSelection = _
            CType(dte.ActiveDocument.Selection, TextSelection)
        Dim fun As CodeFunction = _
            CType(sel.ActivePoint.CodeElement( _
            vsCMElement.vsCMElementFunction), CodeFunction)

        If fun.IsShared Then
            MsgBox(fun.Name & " is an instance method.")
        Else
            MsgBox(fun.Name & " is not an instance method.")
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
 public void IsSharedExample(DTE2 dte)
{
    // Before running this example, open a code document from a project
    // and place the insertion point inside a function.
    try
    {
        // Retrieve the CodeFunction at the insertion point.
        TextSelection sel = 
            (TextSelection)dte.ActiveDocument.Selection;
        CodeFunction fun = 
            (CodeFunction)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementFunction);

        if (fun.IsShared)
            MessageBox.Show(fun.Name + " is an instance method.");
        else
            MessageBox.Show(fun.Name + " is not an instance method.");
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

請參閱

參考

CodeFunction 介面

EnvDTE 命名空間

其他資源

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

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

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