XObject.Annotation Méthode

Définition

Surcharges

Nom Description
Annotation(Type)

Obtient le premier objet d’annotation du type spécifié à partir de ce XObject.

Annotation<T>()

Obtient le premier objet d’annotation du type spécifié à partir de ce XObject.

Annotation(Type)

Source:
XObject.cs
Source:
XObject.cs
Source:
XObject.cs
Source:
XObject.cs
Source:
XObject.cs

Obtient le premier objet d’annotation du type spécifié à partir de ce XObject.

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

Paramètres

type
Type

Type de l’annotation à récupérer.

Retours

Object Qui contient le premier objet d’annotation qui correspond au type spécifié, ou null si aucune annotation n’est du type spécifié.

Exemples

L’exemple suivant ajoute une annotation à un XElement. Il récupère ensuite l’annotation, en spécifiant le type à récupérer.

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

Cet exemple produit la sortie suivante :

T1

Voir aussi

S’applique à

Annotation<T>()

Source:
XObject.cs
Source:
XObject.cs
Source:
XObject.cs
Source:
XObject.cs
Source:
XObject.cs

Obtient le premier objet d’annotation du type spécifié à partir de ce XObject.

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

Paramètres de type

T

Type de l’annotation à récupérer.

Retours

T

Premier objet d’annotation qui correspond au type spécifié ou null si aucune annotation n’est du type spécifié.

Exemples

L’exemple suivant ajoute une annotation à un élément, puis le récupère via cette méthode.

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

Cet exemple produit la sortie suivante :

T1

Voir aussi

S’applique à