Game Development Reference
In-Depth Information
{
List<SortablePair> propertyList = new List<SortablePair>();
PropertyDescriptorCollection descList = TypeDescriptor.GetProperties(component,
attrib);
foreach (PropertyDescriptor descriptor in descList)
{
Attribute attribute
= descriptor.Attributes[typeof(PropertyOrderAttribute)];
if (attribute != null)
{
PropertyOrderAttribute orderAttribute = (PropertyOrderAttribute)attribute;
propertyList.Add(new SortablePair(descriptor.Name,
orderAttribute.Order));
}
else
{
propertyList.Add(new SortablePair(descriptor.Name, 0));
}
}
propertyList.Sort();
List<String> propertyNames = new List<String>();
foreach (SortablePair sortablePair in propertyList)
{
propertyNames.Add(sortablePair.Name);
}
return descriptorList.Sort(propertyNames.ToArray());
}
}
Using the type converter class is fairly easy. Just decorate your class declaration
with the attribute, as shown in the following code. Then decorate your properties
with a PropertyOrder attribute to specify the sort order.
Search Nedrilad ::




Custom Search