Attribute Driven Capabilities
One of the foundations of Morphfolia is the use of attributes to provide a flexible and extensible system.
Attributes are used to:
- Expose class properties (in page layouts and skins) dynamically to the UI, so that users can set properties values (which are then stored in the custom properties area).
- Provide ‘self documenting’ code: appSettings and logging event ids can be decorated with attributes that are read by functionality that displays the information to administrators.
- In all the cases above, attributes are used to provide both technical and human readable information, such as suggested usage and default values.
- Developers can leverage the attributes within their own systems thus providing useful information to end users and operations staff with minimal effort.
There are a few different attributes already defined in Morphfolia which allow you to identify Page Layouts, Skin Providers, Custom Properties, AppSettings, Event Ids for system logging and more. Here's an example of a couple of properties used to decorate custom properties: [AttributeUsage(AttributeTargets.Property)]
public class IsCustomProperty : Attribute
{
public IsCustomProperty()
{
}
public static string AttributeIdentifier = "+Attributes+IsCustomProperty";
}
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]
public class PropertyFriendlyNameAttribute : Attribute
{
public PropertyFriendlyNameAttribute(string friendlyName)
{
this.friendlyName = friendlyName;
}
private string friendlyName;
public string FriendlyName
{
get { return friendlyName; }
set { friendlyName = value; }
}
}
You then identify your custom properties by decorating them with the IsCustomProperty attribute. You can also decorate them with additonal metadata useful to end-users, such as the 'friendly name' of the property, expected usage, and so on. Below, you can see the attributes declared above are actually used: private string tableInlineStyle = string.Empty;
[IsCustomProperty,
PropertyFriendlyName("Table Style"),
PropertyDescription(Descriptions.Style),
PropertySuggestedUsage(SuggestedUsageNotes.Style)]
public string TableInlineStyle
{
get { return tableInlineStyle; }
set { tableInlineStyle = value; }
}
private string cellR0C0InlineStyle = string.Empty;
[IsCustomProperty,
PropertyFriendlyName("R0C0 Style"),
PropertyDescription(Descriptions.Style),
PropertySuggestedUsage(SuggestedUsageNotes.Style)]
public string CellR0C0InlineStyle
{
get { return cellR0C0InlineStyle; }
set { cellR0C0InlineStyle = value; }
}
Below is a screen-shot of part of the page edit screen, which uses these attributes to dynamically generate UI for setting custom properties; you can see the "Table Style" and "R0C0 Style" properties in use - with metadata as defined by using the attributes:
%202.3.0.0.jpg)
|