Custom Properties Support
Custom Properties Support
The plugins can register (extra) properties for solution items. These properties can be edited using the property grid and are stored in the solution files.
The Type Manager service contains a method to register properties and another one to retrieve all properties registered (by the plugins) for a type. A reference to this service can be obtained by the plugin in the initialization method using the Unity Container.
DepProperty RegisterProperty(Type ownerType, string name, Type type)
Registers a new property for the specified type.
- ownerType is the type for which the property will be registered. If ownerType is an interface the property will be available for all classes which implement that interface. If ownerType is a class the property will be available for all classes which are derived from it. For example if ownerType is typeof(IScene) the property will be available for all scenes and composites in the solution.
- name specifies the name of the property.
- type specifies the type of the property. For example typeof(string) or typeof(float). The object returned by this method should be stored by the plugin because it is required to get and set the value of the property.
public DepProperty ReqIdProperty;
public void Initialize(IUnityContainer unityContainer)
{
var typeManager = unityContainer.Resolve<ITypeManagerSvc>();
this.ReqIdProperty = typeManager.RegisterProperty(typeof(IScene), "ReqId", typeof(string));
}
public void OnSolutionChanged(SceneComposer.SDKInterface.Solution.ISolution solution)
{
foreach (var scene in solution.Scenes)
{
//get property value
var reqId = scene.GetValue(this.ReqIdProperty) as string;
//set property value
scene.SetValue(this.ReqIdProperty, "REQ_ID_");
//reset property value
scene.UnsetValue(this.ReqIdProperty);
}
}
IEnumerable<DepProperty> GetRegisteredProperties(Type ownerType)
Returns an enumerable with all the custom properties registered (by plugins) for a specific type including those registered by other plugins and those registered for subtypes of ownerType.