Game Development Reference
In-Depth Information
[CategoryAttribute(“Employee Information”),
DescriptionAttribute(“True or false value indicating a probationary period.”),
PropertyOrder(2)]
public bool Probationary
{
get { return probationary; }
set { probationary = value; }
}
}
Ordering Properties
Strangely enough, there is no attribute that handles the ordering of properties in
the PropertyGrid . There is, however, a way we can make our own attribute and
custom type converter that can accomplish this for us. First, we will define an
attribute that we can use to specify the sort order for properties in a class.
[AttributeUsage(AttributeTargets.Property)]
public class PropertyOrderAttribute : Attribute
{
private int order;
public PropertyOrderAttribute(int order)
{
this.order = order;
}
public int Order
{
get { return order; }
}
}
The following code describes a custom type converter class that interrogates the
PropertyOrder attribute in class properties, sorts the property list based on the values,
and returns a descriptor list that can tell the PropertyGrid the order to display the
properties in.
public class PropertyOrderConverter : ExpandableObjectConverter
{
internal class SortablePair : IComparable<SortablePair>
{
private int order;
Search Nedrilad ::




Custom Search