XObject.Annotation 메서드

정의

오버로드

Name Description
Annotation(Type)

지정된 형식의 첫 번째 주석 개체를 이 XObject주석에서 가져옵니다.

Annotation<T>()

지정된 형식의 첫 번째 주석 개체를 이 XObject주석에서 가져옵니다.

Annotation(Type)

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

지정된 형식의 첫 번째 주석 개체를 이 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

매개 변수

type
Type

검색할 주석의 형식입니다.

반품

Object 지정된 형식과 일치하는 첫 번째 주석 개체를 포함하거나 null 지정된 형식의 주석이 없는 경우 해당 개체입니다.

예제

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

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

T1

추가 정보

적용 대상

Annotation<T>()

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

지정된 형식의 첫 번째 주석 개체를 이 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

형식 매개 변수

T

검색할 주석의 형식입니다.

반품

T

지정된 형식과 일치하는 첫 번째 주석 개체이거나 null 지정된 형식의 주석이 없는 경우입니다.

예제

다음 예제에서는 요소에 주석을 추가한 다음 이 메서드를 통해 검색합니다.

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

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

T1

추가 정보

적용 대상