XObject.Annotations Yöntem
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Annotations(Type) |
Bu XObjectiçin belirtilen türdeki ek açıklamaların koleksiyonunu alır. |
Annotations<T>() |
Bu XObjectiçin belirtilen türdeki ek açıklamaların koleksiyonunu alır. |
- Kaynak:
- XObject.cs
- Kaynak:
- XObject.cs
- Kaynak:
- XObject.cs
Bu XObjectiçin belirtilen türdeki ek açıklamaların koleksiyonunu alır.
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>
Public Function Annotations (type As Type) As IEnumerable(Of Object)
Parametreler
- type
- Type
Alınacak ek açıklamaların türü.
Döndürülenler
Bunlardan IEnumerable<T> biri Object , bu XObjectiçin belirtilen türle eşleşen ek açıklamaları içerir.
Örnekler
Aşağıdaki örnek, öğesine XElementbazı ek açıklamalar ekler ve ardından bu yöntemi kullanarak bir ek açıklama koleksiyonu alır.
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
Bu örnek aşağıdaki çıkışı oluşturur:
T1
T2
----
abc
def
Ayrıca bkz.
Şunlara uygulanır
.NET 9 ve diğer sürümler
Ürün | Sürümler |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
- Kaynak:
- XObject.cs
- Kaynak:
- XObject.cs
- Kaynak:
- XObject.cs
Bu XObjectiçin belirtilen türdeki ek açıklamaların koleksiyonunu alır.
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 Function Annotations(Of T As Class) () As IEnumerable(Of T)
Public Iterator Function Annotations(Of T As Class) () As IEnumerable(Of T)
Tür Parametreleri
- T
Alınacak ek açıklamaların türü.
Döndürülenler
IEnumerable<T> Bu XObjectöğesine yönelik ek açıklamaları içeren bir .
Örnekler
Aşağıdaki örnek, bir öğedeki ek açıklamaları almak için bu yöntemi kullanır.
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
Bu örnek aşağıdaki çıkışı oluşturur:
T1
T2
----
abc
def
Ayrıca bkz.
Şunlara uygulanır
.NET 9 ve diğer sürümler
Ürün | Sürümler |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
.NET Standard | 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1 |
UWP | 10.0 |
.NET geri bildirimi
.NET, açık kaynak bir projedir. Geri bildirim sağlamak için bir bağlantı seçin: