XObject.Annotations Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Överlagringar
| Name | Description |
|---|---|
| Annotations(Type) |
Hämtar en samling anteckningar av den angivna typen för den här XObject. |
| Annotations<T>() |
Hämtar en samling anteckningar av den angivna typen för den här XObject. |
Annotations(Type)
- Källa:
- XObject.cs
- Källa:
- XObject.cs
- Källa:
- XObject.cs
- Källa:
- XObject.cs
- Källa:
- XObject.cs
Hämtar en samling anteckningar av den angivna typen för den här XObject.
public:
System::Collections::Generic::IEnumerable<System::Object ^> ^ Annotations(Type ^ type);
public System.Collections.Generic.IEnumerable<object> Annotations(Type type);
member this.Annotations : Type -> seq<obj>
Public Function Annotations (type As Type) As IEnumerable(Of Object)
Parametrar
- type
- Type
Typen av anteckningar som ska hämtas.
Returer
En IEnumerable<T> av Object dessa innehåller anteckningarna som matchar den angivna typen för den här XObject.
Exempel
I följande exempel läggs några anteckningar till i en XElementoch hämtar sedan en samling anteckningar med hjälp av den här metoden.
public class MyAnnotation
{
private string tag;
public string Tag { get { return tag; } set { tag = value; } }
public MyAnnotation(string tag)
{
this.tag = tag;
}
}
class Program
{
static void Main(string[] args)
{
XElement root = new XElement("Root", "content");
root.AddAnnotation(new MyAnnotation("T1"));
root.AddAnnotation(new MyAnnotation("T2"));
root.AddAnnotation("abc");
root.AddAnnotation("def");
IEnumerable<object> annotationList;
annotationList = root.Annotations(typeof(MyAnnotation));
foreach (object ma in annotationList)
Console.WriteLine(((MyAnnotation)ma).Tag);
Console.WriteLine("----");
IEnumerable<object> stringAnnotationList;
stringAnnotationList = root.Annotations(typeof(string));
foreach (object str in stringAnnotationList)
Console.WriteLine((string)str);
}
}
Public Class MyAnnotation
Private _tag As String
Property Tag() As String
Get
Return Me._tag
End Get
Set(ByVal Value As String)
Me._tag = Value
End Set
End Property
Public Sub New(ByVal tag As String)
Me._tag = tag
End Sub
End Class
Module Module1
Sub Main()
Dim root As XElement = <Root>content</Root>
root.AddAnnotation(New MyAnnotation("T1"))
root.AddAnnotation(New MyAnnotation("T2"))
root.AddAnnotation("abc")
root.AddAnnotation("def")
Dim annotationList As IEnumerable(Of Object)
annotationList = root.Annotations(GetType(MyAnnotation))
For Each ma As MyAnnotation In annotationList
Console.WriteLine(ma.Tag)
Next
Console.WriteLine("----")
Dim stringAnnotationList As IEnumerable(Of Object)
stringAnnotationList = root.Annotations(GetType(String))
For Each str As String In stringAnnotationList
Console.WriteLine(str)
Next
End Sub
End Module
Det här exemplet genererar följande utdata:
T1
T2
----
abc
def
Se även
Gäller för
Annotations<T>()
- Källa:
- XObject.cs
- Källa:
- XObject.cs
- Källa:
- XObject.cs
- Källa:
- XObject.cs
- Källa:
- XObject.cs
Hämtar en samling anteckningar av den angivna typen för den här XObject.
public:
generic <typename T>
where T : class System::Collections::Generic::IEnumerable<T> ^ Annotations();
public System.Collections.Generic.IEnumerable<T> Annotations<T>() where T : class;
member this.Annotations : unit -> seq<'T (requires 'T : null)> (requires 'T : null)
Public Function Annotations(Of T As Class) () As IEnumerable(Of T)
Public Iterator Function Annotations(Of T As Class) () As IEnumerable(Of T)
Typparametrar
- T
Typen av anteckningar som ska hämtas.
Returer
En IEnumerable<T> som innehåller anteckningarna för den här XObject.
Exempel
I följande exempel används den här metoden för att hämta anteckningar på ett element.
public class MyAnnotation {
private string tag;
public string Tag {get{return tag;} set{tag=value;}}
public MyAnnotation(string tag) {
this.tag = tag;
}
}
class Program {
static void Main(string[] args) {
XElement root = new XElement("Root", "content");
root.AddAnnotation(new MyAnnotation("T1"));
root.AddAnnotation(new MyAnnotation("T2"));
root.AddAnnotation("abc");
root.AddAnnotation("def");
IEnumerable<MyAnnotation> annotationList;
annotationList = root.Annotations<MyAnnotation>();
foreach (MyAnnotation ma in annotationList)
Console.WriteLine(ma.Tag);
Console.WriteLine("----");
IEnumerable<string> stringAnnotationList;
stringAnnotationList = root.Annotations<string>();
foreach (string str in stringAnnotationList)
Console.WriteLine(str);
}
}
Public Class MyAnnotation
Private _tag As String
Property Tag() As String
Get
Return Me._tag
End Get
Set(ByVal Value As String)
Me._tag = Value
End Set
End Property
Public Sub New(ByVal tag As String)
Me._tag = tag
End Sub
End Class
Module Module1
Sub Main()
Dim root As XElement = <Root>content</Root>
root.AddAnnotation(New MyAnnotation("T1"))
root.AddAnnotation(New MyAnnotation("T2"))
root.AddAnnotation("abc")
root.AddAnnotation("def")
Dim annotationList As IEnumerable(Of MyAnnotation)
annotationList = root.Annotations(Of MyAnnotation)()
For Each ma As MyAnnotation In annotationList
Console.WriteLine(ma.Tag)
Next
Console.WriteLine("----")
Dim stringAnnotationList As IEnumerable(Of String)
stringAnnotationList = root.Annotations(Of String)()
For Each str As String In stringAnnotationList
Console.WriteLine(str)
Next
End Sub
End Module
Det här exemplet genererar följande utdata:
T1
T2
----
abc
def