Yesterday we introduced the ITask interface. Today we’ll look at a simple implementation of the ITask interface.
I’m not a big fan of reading to be people what they can read for themselves so let’s move on to the code…
[Caveat: this is sample code. This whole series on the blog is sample code. While I am making a reasonable effort with respect to error handling and design, I am not going to take up a lot of room on the blog with comments and error checking that distracts from the intent of the code.]
public class MBFTaskFile : ITask
List<ITaskProperty> m_Properties = new List<ITaskProperty>();
public MBFTaskFile(TasksTask task)
Namespace = task.Namespace;
Class = task.Class;
BaseClass = (task.BaseClass == null) ?
typeof(Microsoft.Build.Utilities.Task).FullName : task.BaseClass;
public IList<ITaskProperty> Properties
public string Namespace
m_Namespace = value;
public string Class
m_Class = value;
public string BaseClass
m_BaseClass = value;
I think the only thing that deserves any explanation is that the default BaseClass, if one is not provided, is Microsoft.Build.Utilities.Task. I choose to implement this in code, instead of in the XSD file because it allows me to validate at compile time instead of catching a problem at runtime.
So that is a basic implementation of the ITask interface.
Tomorrow we’ll look at the ITaskProperty interface. It has a bit more to it.