XObject.AddAnnotation(Object) Método

Definição

Adiciona um objeto à lista de anotações deste XObject.

public:
 void AddAnnotation(System::Object ^ annotation);
public void AddAnnotation(object annotation);
member this.AddAnnotation : obj -> unit
Public Sub AddAnnotation (annotation As Object)

Parâmetros

annotation
Object

Um objeto que contém a anotação a ser adicionada.

Exemplos

O exemplo a seguir adiciona uma anotação a um XElement.

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<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(Of MyAnnotation)(), MyAnnotation)
        Console.WriteLine(ma2.Tag)
    End Sub

End Module

Este exemplo produz a seguinte saída:

T1

Comentários

Observe que as anotações não fazem parte do conjunto de informações; eles não são persistidos ou exibidos por ToString. Além disso, se você importar um Namespace XML para seu projeto de VB e chamar AddAnnotation com o valor de enumeração SaveOptions.OmitDuplicateNamespaces, apenas um elemento conterá o atributo namespace XML em vez de cada elemento. Para obter mais informações, consulte Removendo namespaces duplicados em literais XML.

Aplica-se a

Confira também