CodeDelegate2.IsGeneric 属性
获取委托是否为泛型。
命名空间: EnvDTE80
程序集: EnvDTE80(在 EnvDTE80.dll 中)
语法
声明
ReadOnly Property IsGeneric As Boolean
bool IsGeneric { get; }
property bool IsGeneric {
bool get ();
}
abstract IsGeneric : bool
function get IsGeneric () : boolean
属性值
类型:System.Boolean
一个布尔值,如果委托为泛型,该值为 true,否则为 false。
备注
备注
在进行某些类型的编辑之后,代码模型元素(如类、结构、函数、特性、委托等)的值可能是非确定性的,这意味着不能指望它们的值总是保持不变。有关更多信息,请参见 使用代码模型查找代码 (Visual Basic) 中的“代码模型元素的值可能会更改”一节。
示例
在运行此示例之前,加载一个具有某个类的项目,并插入下行以及代码示例。 在添加了该行和代码示例之后,单击 Delegate 行将插入点放在该行处,然后运行该示例。
[VisualBasic]
Delegate Sub MySubDelegate(ByVal x As Integer)
[C#]
public delegate void MySubDelegate(int x);
[VisualBasic]
Public Sub CodeDelegateExample(ByVal dte As DTE2)
' Before running this example, open a code document from a
' project and place the insertion point inside a class
' definition.
Try
' Retrieve the CodeClass at the insertion point.
Dim sel As TextSelection = _
CType(DTE.ActiveDocument.Selection, TextSelection)
Dim del As CodeDelegate2 = _
CType(sel.ActivePoint.CodeElement( _
vsCMElement.vsCMElementDelegate), CodeDelegate2)
Dim elem As CodeElement2
Dim sb As New System.Text.StringBuilder
' Display the baseclass name of the delegate.
sb.AppendLine("Delegate base class name: " & _
del.BaseClass.Name)
sb.AppendLine("Delegate's access: " & del.Access.ToString)
sb.AppendLine("Children: " & del.Children.Count & " _
Name: " & del.Children.Item(1).Name)
sb.AppendLine("Collection: " & del.Collection.Count)
sb.AppendLine("Delegates:")
For Each elem In del.Collection
sb.AppendLine(" - " & elem.Name)
Next
sb.AppendLine("Comment: " & del.Comment)
sb.AppendLine("Doc Comment: " & del.DocComment)
sb.AppendLine("DTE Parent: " & del.DTE.Name)
sb.AppendLine("Endpoint location: " & _
del.EndPoint.AbsoluteCharOffset)
sb.AppendLine("Infolocation: " & del.InfoLocation.ToString)
sb.AppendLine("Can provide CodeType object? " & _
del.IsCodeType.ToString)
sb.AppendLine("Is Delegate derived? " & _
del.IsDerivedFrom("EnvDTE80"))
sb.AppendLine("Is Delegate a generic? " & del.IsGeneric)
sb.AppendLine("Kind: " & del.Kind.ToString)
sb.AppendLine("Authoring language: " & _
del.Language.ToString)
sb.AppendLine("Name: " & del.Name)
sb.AppendLine("Namespace: " + del.Namespace.Name);
sb.AppendLine("Parameters: " & del.Parameters.Item(1).Name)
sb.AppendLine("Project containing the delegate: " & _
del.ProjectItem.Name)
sb.AppendLine("Prototype for delegate: " & del.Prototype)
sb.AppendLine("Delegate start point offset: " & _
del.StartPoint.LineCharOffset)
sb.AppendLine("Type: " & del.Type.TypeKind.ToString)
MsgBox(sb.ToString)
Catch ex As System.Exception
MsgBox(ex.ToString)
End Try
End Sub
[C#]
public void CodeDelegateExample(DTE2 DTE)
{
try
{
// Retrieve the CodeClass at the insertion point.
TextSelection sel = (TextSelection)
DTE.ActiveDocument.Selection;
CodeDelegate2 del = (CodeDelegate2)
sel.ActivePoint.get_CodeElement
(vsCMElement.vsCMElementDelegate);
System.Text.StringBuilder sb = new System.Text.StringBuilder();
// Display the baseclass name of the delegate.
sb.AppendLine("Delegate base class name: " +
del.BaseClass.Name);
sb.AppendLine("Delegate's access: " + del.Access);
sb.AppendLine("Children: "+del.Children.Count+" Name:
"+del.Children.Item(1).Name);
sb.AppendLine("Collection: "+del.Collection.Count);
sb.AppendLine("Delegates:");
foreach (CodeElement2 elem in del.Collection )
{
sb.AppendLine(" - "+elem.Name);
}
sb.AppendLine("Comment: "+del.Comment);
sb.AppendLine("Attributes:");
foreach (CodeElement2 elem in del.Attributes)
{
sb.AppendLine(" - " + elem.Name);
}
sb.AppendLine("Bases:");
foreach (CodeElement2 elem in del.Bases)
{
sb.AppendLine(" - " + elem.Name);
}
sb.AppendLine("Doc Comment: " + del.DocComment);
sb.AppendLine("DTE Parent: "+del.DTE.Name);
sb.AppendLine("Endpoint location:
"+del.EndPoint.AbsoluteCharOffset);
sb.AppendLine("Infolocation: "+del.InfoLocation);
sb.AppendLine("Can provide CodeType object? "+del.IsCodeType);
sb.AppendLine("Is Delegate derived?
"+del.get_IsDerivedFrom("EnvDTE80"));
sb.AppendLine("Is Delegate a generic? "+del.IsGeneric);
sb.AppendLine("Kind: "+del.Kind);
sb.AppendLine("Authoring language: "+del.Language);
sb.AppendLine("Name: "+del.Name);
sb.AppendLine("Parameters: "+del.Parameters.Item(1).Name);
sb.AppendLine("Namespace: " + del.Namespace.Name);
sb.AppendLine("Project containing the delegate:
"+del.ProjectItem.Name);
sb.AppendLine("Delegate start point offset:
"+del.StartPoint.LineCharOffset);
sb.AppendLine("Type: "+del.Type.TypeKind);
MessageBox.Show(sb.ToString());
}
catch(System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关更多信息,请参见通过部分受信任的代码使用库。