Mega Code Archive

 
Categories / C# / XML LINQ
 

Get the first annotation object of the specified type from this XObject

using System; using System.Xml.Linq; 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);     } }