XObject.AddAnnotation(Object) 메서드

정의

XObject주석 목록에 개체를 추가합니다.

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

매개 변수

annotation
Object

추가할 주석이 들어 있는 개체입니다.

예제

다음 예제에서는 주석을 .에 추가합니다 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

이 예제는 다음과 같은 출력을 생성합니다.

T1

설명

주석은 정보 세트의 일부가 아닙니다. 유지되지 않거나 에 의해 ToString표시되지 않습니다. 또한 XML 네임스페이스를 VB 프로젝트로 가져오고 SaveOptions.OmitDuplicateNamespaces 열거형 값을 사용하여 AddAnnotation을 호출하는 경우 모든 요소 대신 하나의 요소만 XML 네임스페이스 특성을 포함합니다. 자세한 내용은 XML 리터럴에서 중복 네임스페이스 제거를 참조하세요.

적용 대상

추가 정보