XObject.Annotation Methode

Definition

Überlädt

Name Beschreibung
Annotation(Type)

Ruft das erste Anmerkungsobjekt des angegebenen Typs von diesem XObjectab.

Annotation<T>()

Ruft das erste Anmerkungsobjekt des angegebenen Typs von diesem XObjectab.

Annotation(Type)

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

Ruft das erste Anmerkungsobjekt des angegebenen Typs von diesem XObjectab.

public:
 System::Object ^ Annotation(Type ^ type);
public object Annotation(Type type);
public object? Annotation(Type type);
member this.Annotation : Type -> obj
Public Function Annotation (type As Type) As Object

Parameter

type
Type

Der Typ der abzurufenden Anmerkung.

Gibt zurück

Das Object Objekt, das das erste Anmerkungsobjekt enthält, das dem angegebenen Typ entspricht, oder null wenn keine Anmerkung vom angegebenen Typ ist.

Beispiele

Im folgenden Beispiel wird einer XElement. Anschließend wird die Anmerkung abgerufen, wobei der abzurufende Typ angegeben wird.

public class MyAnnotation {
    private string tag;
    public string Tag {get{return tag;} set{tag=value;}}
    public MyAnnotation(string tag) {
        this.tag = tag;
    }
}

public class Program {
    public static void Main(string[] args) {
        MyAnnotation ma = new MyAnnotation("T1");
        XElement root = new XElement("Root", "content");
        root.AddAnnotation(ma);

        MyAnnotation ma2 = (MyAnnotation)root.Annotation(typeof(MyAnnotation));
        Console.WriteLine(ma2.Tag);
    }
}
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 ma As MyAnnotation = New MyAnnotation("T1")
        Dim root As XElement = <Root>content</Root>
        root.AddAnnotation(ma)

        Dim ma2 As MyAnnotation = DirectCast(root.Annotation(GetType(MyAnnotation)), MyAnnotation)
        Console.WriteLine(ma2.Tag)
    End Sub

End Module

Dieses Beispiel erzeugt die folgende Ausgabe:

T1

Weitere Informationen

Gilt für:

Annotation<T>()

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

Ruft das erste Anmerkungsobjekt des angegebenen Typs von diesem XObjectab.

public:
generic <typename T>
 where T : class T Annotation();
public T Annotation<T>() where T : class;
public T? Annotation<T>() where T : class;
member this.Annotation : unit -> 'T (requires 'T : null)
Public Function Annotation(Of T As Class) () As T

Typparameter

T

Der Typ der abzurufenden Anmerkung.

Gibt zurück

T

Das erste Anmerkungsobjekt, das dem angegebenen Typ entspricht, oder null wenn keine Anmerkung vom angegebenen Typ ist.

Beispiele

Im folgenden Beispiel wird einem Element eine Anmerkung hinzugefügt und anschließend über diese Methode abgerufen.

public class MyAnnotation {
    private string tag;
    public string Tag {get{return tag;} set{tag=value;}}
    public MyAnnotation(string tag) {
        this.tag = tag;
    }
}

public class Program {
    public static void Main(string[] args) {
        MyAnnotation ma = new MyAnnotation("T1");
        XElement root = new XElement("Root", "content");
        root.AddAnnotation(ma);

        MyAnnotation ma2 = root.Annotation<MyAnnotation>();
        Console.WriteLine(ma2.Tag);
    }
}
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 ma As MyAnnotation = New MyAnnotation("T1")
        Dim root As XElement = <Root>content</Root>
        root.AddAnnotation(ma)

        Dim ma2 As MyAnnotation = root.Annotation(Of MyAnnotation)()
        Console.WriteLine(ma2.Tag)
    End Sub
End Module

Dieses Beispiel erzeugt die folgende Ausgabe:

T1

Weitere Informationen

Gilt für: