CodeClass2.IsCodeType 属性

获取一个值,该值指示是否可以从此代码类中获取 CodeType 对象。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
ReadOnly Property IsCodeType As Boolean
bool IsCodeType { get; }
property bool IsCodeType {
    bool get ();
}
abstract IsCodeType : bool with get
function get IsCodeType () : boolean

属性值

类型:Boolean
一个布尔值,如果可获取 CodeType 对象,则返回 true;否则返回 false。

备注

IsCodeType 返回该代码类是否为代码类型。 如果是,则可使用查询接口 (QI) 或将该代码元素强制转换为 CodeType 对象。 当 KindvsCMElementClassvsCMElementInterfacevsCMElementDelegatevsCMElementStructvsCMElementEnum 时,此值为 true。

备注

在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。

示例

[C#]

public void CodeClass2IsCodeTypeExample(DTE2 dte2)
{
    // Before running this example, open a code document from a project
    // and place the insertion point within a class definition.
    try
    {   // Get the CodeClass2 at the insertion point.
        TextSelection sel = 
        (TextSelection)dte2.ActiveDocument.Selection;
        CodeClass2 cls = (CodeClass2)sel.ActivePoint.get_CodeElement(
            vsCMElement.vsCMElementClass);

        // Test if element is a code type.
        if (cls.IsCodeType)
        {
            MessageBox.Show("Element is a code type");
            // Test if element is a class.
            if (cls.Kind == vsCMElement.vsCMElementClass)
                MessageBox.Show("This element is a class");
        }
    }
    catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
}

.NET Framework 安全性

请参阅

参考

CodeClass2 接口

EnvDTE80 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例

使用代码模型查找代码 (Visual Basic)

使用代码模型查找代码 (Visual C#)