Language: C#
ClassDescriptor
using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using LinqExtender.Configuration.Serialization; namespace LinqExtender.Configuration { /// <summary> /// Contains details for the class. /// </summary> public class ClassDescriptor { /// <summary> /// Gets/Sets key for the class, normally contains the name of the class. /// </summary> public string Key { get; set; } /// <summary> /// Gets/ Sets the name of the class. /// </summary> public string Name { get; set; } /// <summary> /// Sets the info for each property. /// </summary> internal IDictionary<string, PropertyDescriptor> PropertyDescriptors { get { if (propertyDescriptors == null) propertyDescriptors = new Dictionary<string, PropertyDescriptor>(); return propertyDescriptors; } } private IDictionary<string, PropertyDescriptor> propertyDescriptors; /// <summary> /// Builds and returns the xml element for the class. /// </summary> /// <param name="descriptor"></param> /// <returns></returns> public static implicit operator ClassElement(ClassDescriptor descriptor) { ClassElement element = new ClassElement() { Name = descriptor.Key, EntityName = descriptor.Name }; // creates the Properties collection. element.Properties = new PropertyElement[descriptor.PropertyDescriptors.Count]; int index = 0; foreach (string key in descriptor.PropertyDescriptors.Keys) { PropertyDescriptor propertyDescriptor = descriptor.PropertyDescriptors[key]; PropertyElement propertyElement = new PropertyElement(); propertyElement.Name = propertyDescriptor.Name; foreach (string propName in propertyDescriptor.Properties.Keys) { PropertyInfo info = typeof (PropertyElement).GetProperty(propName); if (info.CanWrite) { info.SetValue(propertyElement, propertyDescriptor.Properties[propName], null); } } element.Properties[index++] = propertyElement; } return element; } } }
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search

