I created a class “TaskVarEx” to encapsulate all the variables with the Serialize method, the default constructor for initial values, an overriding constructor that takes a string parameter to deserialize and Properties to access all the variables. The variables themselves are each private in the serializable struct “Vars” which is public but only instantiated within the scope of the TaskVarEx class. So all of the variables are stuffed into one task variable, the name of that variable is stored in the static variable:
Code: Select all
public const string VARS_EX_NAME = "VARS";
Code: Select all
IEdmTaskProperties props = (IEdmTaskProperties)poCmd.mpoExtra;
…
TaskVarEx taskVars = new TaskVarEx((string)props.GetValEx(TaskVarEx.VARS_EX_NAME));
Code: Select all
taskVars.TaskType
or
taskVars.ShowMenu
Code: Select all
task = (IEdmTaskInstance)poCmd.mpoExtra;
…
task.SetValEx(TaskVarEx.VARS_EX_NAME, taskVars.Serialize());
The add in has been running this way for over a year and I have not yet found issues with this method of encapsulating the task variables. There’s been other issues I’ve addressed, but so far this is working. I my mind it makes the code much simpler to read and a bit more inline with object oriented programming. I’ve been curious is anyone else is doing something similar with their custom task add-in.
Thanks.