O'Reilly logo

Pro LINQ: Language Integrated Query in C# 2008 by Joseph C. Rattz Jr.

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

XML Annotations

The LINQ to XML API provides the ability to associate a user data object with any class inheriting from the XObject class via annotations. This allows the application developer to assign whatever data type object he wants to an element, document, or any other object whose class is derived from the XObject class. The object could be additional keys for an element's data; it could be an object that will parse the element's contents into itself or whatever you need.

Adding Annotations with XObject.AddAnnotation()

Adding annotations is accomplished using the XObject.AddAnnotation method. Here is the prototype:

void XObject.AddAnnotation(object annotation);

Accessing Annotations with XObject.Annotation() or XObject.Annotations() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required