CodeFunction2.IsShared 属性

定义

获取或设置是否可以静态定义项,即该项为此对象类型的全部实例所共有,还是仅此对象专有。

public:
 property bool IsShared { bool get(); void set(bool value); };
public:
 property bool IsShared { bool get(); void set(bool value); };
[System.Runtime.InteropServices.DispId(40)]
public bool IsShared { [System.Runtime.InteropServices.DispId(40)] get; [System.Runtime.InteropServices.DispId(40)] set; }
[<System.Runtime.InteropServices.DispId(40)>]
[<get: System.Runtime.InteropServices.DispId(40)>]
[<set: System.Runtime.InteropServices.DispId(40)>]
member this.IsShared : bool with get, set
Public Property IsShared As Boolean

属性值

Boolean

如果可以共享该方法,则布尔值为 true;否则为 false

实现

属性

示例

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

注解

IsShared 返回或设置方法是与类关联还是与类的实例相关联。 请注意,设置此项可能会产生与语言相关的错误。 尽管 IsShared 返回成功,但并不表示生成的代码更改已成功编译。

备注

在进行了某些类型的编辑之后,代码模型元素(例如类、结构、函数、特性、委托等)的值可能变为非确定性的,这意味着不能确定它们的值始终保持不变。

适用于