Auf Englisch lesen

Teilen über


XObject.Annotations Methode

Definition

Überlädt

Annotations(Type)

Ruft eine Auflistung von Anmerkungen des angegebenen Typs für dieses XObject ab.

Annotations<T>()

Ruft eine Auflistung von Anmerkungen des angegebenen Typs für dieses XObject ab.

Annotations(Type)

Quelle:
XObject.cs
Quelle:
XObject.cs
Quelle:
XObject.cs

Ruft eine Auflistung von Anmerkungen des angegebenen Typs für dieses XObject ab.

C#
public System.Collections.Generic.IEnumerable<object> Annotations (Type type);

Parameter

type
Type

Der Typ der abzurufenden Anmerkungen.

Gibt zurück

Ein IEnumerable<T> vom Typ Object, das die Anmerkungen enthält, die mit dem angegebenen Typ für dieses XObject übereinstimmen.

Beispiele

Im folgenden Beispiel werden einige Anmerkungen zu einem XElementhinzugefügt, und ruft dann mithilfe dieser Methode eine Auflistung von Anmerkungen ab.

C#
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);  
    }  
}  

Dieses Beispiel erzeugt die folgende Ausgabe:

T1  
T2  
----  
abc  
def  

Weitere Informationen

Gilt für:

.NET 9 und andere Versionen
Produkt Versionen
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

Annotations<T>()

Quelle:
XObject.cs
Quelle:
XObject.cs
Quelle:
XObject.cs

Ruft eine Auflistung von Anmerkungen des angegebenen Typs für dieses XObject ab.

C#
public System.Collections.Generic.IEnumerable<T> Annotations<T> () where T : class;

Typparameter

T

Der Typ der abzurufenden Anmerkungen.

Gibt zurück

Ein IEnumerable<T>, das die Anmerkungen für dieses XObject enthält.

Beispiele

Im folgenden Beispiel wird diese Methode verwendet, um Anmerkungen für ein Element abzurufen.

C#
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);  
    }  
}  

Dieses Beispiel erzeugt die folgende Ausgabe:

T1  
T2  
----  
abc  
def  

Weitere Informationen

Gilt für:

.NET 9 und andere Versionen
Produkt Versionen
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0