CodeClass2.IsDerivedFrom 属性 (String)
获取一个值,该值指示此代码类是否以另一个代码类作为其基类。
命名空间: EnvDTE80
程序集: EnvDTE80(在 EnvDTE80.dll 中)
语法
声明
ReadOnly Property IsDerivedFrom ( _
FullName As String _
) As Boolean
Get
bool this[
string FullName
] { get; }
property bool IsDerivedFrom[String^ FullName] {
bool get (String^ FullName);
}
abstract IsDerivedFrom : bool
JScript 不支持索引属性。
参数
- FullName
类型:System.String
必选。要在此类型的沿袭中搜索的类型。
属性值
类型:System.Boolean
一个布尔值,如果代码类以另一个代码类作为其基类,该值为 true;否则为 false。
实现
CodeClass.IsDerivedFrom[String]
备注
提示
在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。 有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。
示例
[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
[C#]
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.get_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.get_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 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。