I was goofing around with some reflection stuff, and wanted to use LINQ to build an xml document for me. It started off as three different steps, and whittled its way down to one.
- Gets a list of all of the properties in the current class that have the [ServiceProperty] attribute
- Creates an XDocument containing information about the property including the value, and all of the meta-data added by the [ServiceProperty] attribute
The only thing I don’t like is that it builds the entire wrapper, even if attribute is null. When the attribute is null, we don’t care about anything, and should just continue. But, as is, property.GetValue() executes even when we don’t need it.