I'm writing a plug-in for an application with a .NET API. The objects of the program can have custom attributes applied through two methods of the root object type which assign key/value pairs to the objects.
BaseAppObject.GetUserString(string key, string value);
BaseAppObject.SetUserString(string key, ref string value);
I'm creating a set of my own custom classes that act as wrapper classes around instances of BaseAppObject. All my classes are derived from a class Node which has a field to store a reference to a BaseAppObject. Other properties of Node and types that derive from Node use the GetUserString and SetUserString methods of the associated BaseAppObject instance to read or write property values directly to or from the associated BaseAppObjects. This way when the application is closed all the information needed to regenerate these wrapper classes later is stored in the actual document.
Here's a simplified version of what I have for my base class constructor.
public abstract class Node
{
BaseAppObject _baseObject;
public Node(BaseAppObject baseObject, string name)
{
this._baseObject = baseObject;
this.Name = name;
}
public string Name
{
get {
string name = "";
_baseObject.GetUserString("CPName", ref name);
return name;
}
set {
_baseObject.SetUserString("CPName", value);
}
}
}
Other classes derived from Node may add additional properties like this.
public CustomClass:Node
{
public CustomClass(BaseAppObject baseObj,string name, string color):base(baseObj,name)
public string Color
{
get {
string name = "";
this.BaseObject.GetUserString("Color", ref name);
return name;
}
set {
this.BaseObject.SetUserString("Color", value);
}
}
}
I'm trying to figure out the best way to setup the constructors and other methods of my classes to initiate and regenerate instances of my classes. I need to be able to create new instances of my classes based of clean instances of BaseAppObject that have no user strings defined, and also regenerate previously existing instance of my class based on the user strings stored in a existing BaseAppObject.