Some Refactorings

Some of the properties that were created look something like this:

public string Category
{
 get
 {
  if (this.Properties.Contains("Category"))
   return this.Properties["Category"].GetValue<string>();
  else
   return null;
 }
 set
 {
  if (this.Properties.Contains("Category"))
   this.Properties["Category"].Value = value;
  else
   this.Properties.Add(new MetadataProperty("Category", value));
 }
}

I created a get and set method to do the same thing that you see above, which reduces the lines of code, but uses generics to be type-specific.  The new version of the property looks like this:

public string Category
{
 get { return this.GetPropertyValue<string>("Category"); }
 set { this.SetPropertyValue<string>("Category", value); }
}

I also had an event argument class that I could get rid of.  There will be other slight changes that need made like this, like renaming method, object, or property names that will be made.

Some other refactorings that were found, as I work through  the code to add triggers/values (to appear next), I found that there will be changes to the Task object.  PercentageDue will not be needed, as there will be many possible values that are due, as well as the complete method.  Complete method will be moved to a lower level during refactoring that will make it more useful.  I don't know completely how that will work, so these values will be refactored later; however, I know they need to change, and they've been identified.

I also have a TaskCollection class, which has three special events that I used:  TaskAdded, TaskCleared, and TaskRemoved, which I used in the application; however, the MetadataEntityCollection generic class has these methods, as well as going beyond, to handle this capability.  So, I plan to remove this class.  I did a find on the TaskAdded event, and found it in one place in a form.  So I changed the event declarations to my base class:

MGR.Tasks.ItemAdded += new DataEventHandler<Task>(Tasks_ItemAdded);
MGR.Tasks.ItemCleared += new EventHandler(Tasks_ItemCleared);
MGR.Tasks.ItemRemoved += new DataEventHandler<Task>(Tasks_ItemRemoved);

I moved the code so it appears as this:

void Tasks_ItemAdded(object sender, DataEventArgs<Task> e)
{
    //Code to add a new task in the Task interface
}

void Tasks_ItemCleared(object sender, EventArgs e)
{
    //Code to clear tasks in Task interface
}

void Tasks_ItemRemoved(object sender, DataEventArgs<Task> e)
{
    //Code to remove task in Task interface
}

Tasks_ItemAdded(object sender, DataEventArgs<Task> e)
{
    //Code to add a new task in the Task interface
}

void Tasks_ItemCleared(object sender, EventArgs e)
{
    //Code to clear tasks in Task interface
}

void Tasks_ItemRemoved(object sender, DataEventArgs<Task> e)
{
    //Code to remove task in Task interface
}

void Tasks_ItemCleared(object sender, EventArgs e)
{
    //Code to clear tasks in Task interface
}

void Tasks_ItemRemoved(object sender, DataEventArgs<Task> e)
{
    //Code to remove task in Task interface
}

void Tasks_ItemRemoved(object sender, DataEventArgs<Task> e)
{
    //Code to remove task in Task interface
}

Comments

No Comments