XObject.Annotations XObject.Annotations XObject.Annotations XObject.Annotations Method

정의

오버로드

Annotations(Type) Annotations(Type) Annotations(Type)

XObject에서 지정된 형식의 주석 컬렉션을 가져옵니다.Gets a collection of annotations of the specified type for this XObject.

Annotations<T>() Annotations<T>() Annotations<T>() Annotations<T>()

XObject에서 지정된 형식의 주석 컬렉션을 가져옵니다.Gets a collection of annotations of the specified type for this XObject.

Annotations(Type) Annotations(Type) Annotations(Type)

XObject에서 지정된 형식의 주석 컬렉션을 가져옵니다.Gets a collection of annotations of the specified type for this XObject.

public:
 System::Collections::Generic::IEnumerable<System::Object ^> ^ Annotations(Type ^ type);
public System.Collections.Generic.IEnumerable<object> Annotations (Type type);
member this.Annotations : Type -> seq<obj>

매개 변수

type
Type Type Type Type

검색할 주석의 형식입니다.The type of the annotations to retrieve.

반환

IEnumerable<T>에서 지정된 형식과 일치하는 주석이 들어 있는 ObjectXObject입니다.An IEnumerable<T> of Object that contains the annotations that match the specified type for this XObject.

예제

다음 예제에서는 일부 주석을 추가 XElement,이 메서드를 사용 하 여 주석의 컬렉션을 검색 합니다.The following example adds some annotations to an XElement, then retrieves a collection of annotations by using this method.

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

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

        IEnumerable<object> annotationList;  
        annotationList = root.Annotations(typeof(MyAnnotation));  
        foreach (object ma in annotationList)  
            Console.WriteLine(((MyAnnotation)ma).Tag);  
        Console.WriteLine("----");  

        IEnumerable<object> stringAnnotationList;  
        stringAnnotationList = root.Annotations(typeof(string));  
        foreach (object str in stringAnnotationList)  
            Console.WriteLine((string)str);  
    }  
}  
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 root As XElement = <Root>content</Root>  
        root.AddAnnotation(New MyAnnotation("T1"))  
        root.AddAnnotation(New MyAnnotation("T2"))  
        root.AddAnnotation("abc")  
        root.AddAnnotation("def")  

        Dim annotationList As IEnumerable(Of Object)  
        annotationList = root.Annotations(GetType(MyAnnotation))  
        For Each ma As MyAnnotation In annotationList  
            Console.WriteLine(ma.Tag)  
        Next  

        Console.WriteLine("----")  

        Dim stringAnnotationList As IEnumerable(Of Object)  
        stringAnnotationList = root.Annotations(GetType(String))  
        For Each str As String In stringAnnotationList  
            Console.WriteLine(str)  
        Next  
    End Sub  
End Module  

이 예제는 다음과 같은 출력을 생성합니다.This example produces the following output:

T1  
T2  
----  
abc  
def  
추가 정보

Annotations<T>() Annotations<T>() Annotations<T>() Annotations<T>()

XObject에서 지정된 형식의 주석 컬렉션을 가져옵니다.Gets a collection of annotations of the specified type for this XObject.

public:
generic <typename T>
 where T : class System::Collections::Generic::IEnumerable<T> ^ Annotations();
public System.Collections.Generic.IEnumerable<T> Annotations<T> () where T : class;
member this.Annotations : unit -> seq<'T (requires 'T : null)> (requires 'T : null)
Public Iterator Function Annotations(Of T As Class) () As IEnumerable(Of T)

형식 매개 변수

T

검색할 주석의 형식입니다.The type of the annotations to retrieve.

반환

IEnumerable<T>의 주석이 들어 있는 XObject입니다.An IEnumerable<T> that contains the annotations for this XObject.

예제

다음 예제에서는이 메서드를 사용 하 여 요소에 주석을 검색 합니다.The following example uses this method to retrieve annotations on an element.

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

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

        IEnumerable<MyAnnotation> annotationList;  
        annotationList = root.Annotations<MyAnnotation>();  
        foreach (MyAnnotation ma in annotationList)  
            Console.WriteLine(ma.Tag);  
        Console.WriteLine("----");  

        IEnumerable<string> stringAnnotationList;  
        stringAnnotationList = root.Annotations<string>();  
        foreach (string str in stringAnnotationList)  
            Console.WriteLine(str);  
    }  
}  
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 root As XElement = <Root>content</Root>  
        root.AddAnnotation(New MyAnnotation("T1"))  
        root.AddAnnotation(New MyAnnotation("T2"))  
        root.AddAnnotation("abc")  
        root.AddAnnotation("def")  

        Dim annotationList As IEnumerable(Of MyAnnotation)  
        annotationList = root.Annotations(Of MyAnnotation)()  
        For Each ma As MyAnnotation In annotationList  
            Console.WriteLine(ma.Tag)  
        Next  
        Console.WriteLine("----")  

        Dim stringAnnotationList As IEnumerable(Of String)  
        stringAnnotationList = root.Annotations(Of String)()  
        For Each str As String In stringAnnotationList  
            Console.WriteLine(str)  
        Next  
    End Sub  
End Module  

이 예제는 다음과 같은 출력을 생성합니다.This example produces the following output:

T1  
T2  
----  
abc  
def  
추가 정보

적용 대상