CodeClass.IsDerivedFrom 属性

返回用于指示 CodeClass 对象是否以另一对象作为基的值。

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

语法

声明
ReadOnly Property IsDerivedFrom ( _
    FullName As String _
) As Boolean
bool this[
    string FullName
] { get; }
property bool IsDerivedFrom[String^ FullName] {
    bool get (String^ FullName);
}
abstract IsDerivedFrom : 
        FullName:string -> bool with get
JScript 不支持索引属性。

参数

  • FullName
    类型:String

    必选。 要在此类型的沿袭中搜索的类型。

属性值

类型:Boolean
一个布尔值,如果 CodeClass 对象将另一个对象作为基,则为 true;否则为 false。

备注

备注

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

示例

 Sub IsDerivedFromExample(ByVal dte As DTE2)

    ' Before running this example, open a code document from a project.
    Try
        Dim projItem As ProjectItem = dte.ActiveDocument.ProjectItem
        Dim cm As CodeModel = projItem.ContainingProject.CodeModel

        ' Create a new class.
        Dim cls1 As CodeClass = cm.AddClass("BaseClass", projItem.Name)

        ' Derive a class from the newly created class.
        Dim bases() As Object = {cls1.FullName}
        Dim cls2 As CodeClass = cm.AddClass("DerivedClass", _
            projItem.Name, -1, bases)

        Dim derived As String
        If cls1.IsDerivedFrom(cls2.FullName) Then
            derived &= cls1.Name & " is derived from " & _
                cls2.Name & vbCrLf
        Else
            derived &= cls1.Name & " is not derived from " & _
                cls2.Name & vbCrLf
        End If

        If cls2.IsDerivedFrom(cls1.FullName) Then
            derived &= cls2.Name & " is derived from " & _
                cls1.Name & vbCrLf
        Else
            derived &= cls2.Name & " is not derived from " & _
                cls1.Name & vbCrLf
        End If

        MsgBox(derived)
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
public void IsDerivedFromExample(DTE2 dte)
{
    // Before running this example, open a code document from 
    // a project.
    try
    {
        ProjectItem projItem = dte.ActiveDocument.ProjectItem;
        CodeModel cm = projItem.ContainingProject.CodeModel;

        // Create a new class.
        CodeClass cls1 = cm.AddClass("BaseClass", projItem.Name, -1, 
            null, null, vsCMAccess.vsCMAccessPublic);

        // Derive a class from the newly created class.
        object[] bases = {cls1.FullName};
        CodeClass cls2 = cm.AddClass("DerivedClass", projItem.Name, -1, 
            bases, null, vsCMAccess.vsCMAccessPublic);
        string derived = "";

        if (cls1.IsDerivedFrom(cls2.FullName))
            derived += cls1.Name + " is derived from " + 
                cls2.Name + "\n";
        else
            derived += cls1.Name + " is not derived from " + 
                cls2.Name + "\n";

        if (cls2.IsDerivedFrom(cls1.FullName))
            derived += cls2.Name + " is derived from " + 
                cls1.Name + "\n";
        else
            derived += cls2.Name + " is not derived from " + 
                cls1.Name + "\n";

        MessageBox.Show(derived);
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

.NET Framework 安全性

请参阅

参考

CodeClass 接口

EnvDTE 命名空间

其他资源

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

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

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