CodeDelegate2.Comment 屬性
設定並取得與 CodeDelegate2 關聯的註解。
命名空間: EnvDTE80
組件: EnvDTE80 (在 EnvDTE80.dll 中)
語法
'宣告
Property Comment As String
string Comment { get; set; }
property String^ Comment {
String^ get ();
void set (String^ value);
}
abstract Comment : string with get, set
function get Comment () : String
function set Comment (value : String)
屬性值
型別:System.String
包含與 CodeDelegate2 相關之註解的字串。
備註
Comment 會設定或傳回標頭註解。傳回時,這些文字並不包含任何註解語法。此文字是根據語言的註解樣式,從來源衍生而來,用以指定有多少舊版的來源註解可做為委派的標頭註解。
設定好之後,Comment 會嘗試使用行導向式語法取代分隔式語法,保持任何現有註解的樣式。例如,Comment 會保留行導向式語法前端的任何縮排、保留註解是要與委派接觸或是要以空白行分隔等等。
注意事項 |
---|
在特定類型的編輯之後,程式碼模型項目 (例如類別、結構、函式、屬性、委派等) 的值可能不具決定性,表示其值不一定維持相同。如需詳細資訊,請參閱使用程式碼模型探索程式碼 (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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。