Compartilhar via


MSBuild Task Generator: Part 2. The basic interfaces.

Last time we looked at the XSD file and a sample rendering from XML to C#.  This time I’ll introduce the primary interfaces used in the rendering process.

 

First we have an ITask.

 

namespace GenTaskLib

{

      public interface ITask

      {

            IList<ITaskProperty> Properties

            {

                  get;

            }

            string Namespace

            {

                  get;

            }

            string Class

            {

                  get;

            }

            string BaseClass

            {

                  get;

            }

      }

}

 

An ITask contains a Namespace, Class and BaseClass as well as a collection of ITaskProperty items (which we’ll see next).  These map directly to the Namespace, Class and BaseClass attributes of the Task element in the XSD.

 

Next we have ITaskProperty

 

namespace GenTaskLib

{

      public interface ITaskProperty

      {

            string Default

            {

                  get;

            }

            bool IsArray

            {

                  get;

            }

            string Name

            {

                  get;

            }

            string Range

            {

                  get;

            }

            bool Required

            {

                  get;

            }

            Type Type

            {

            get;

            }

      }

}

 

An ITaskProperty, like an ITask, is a mirroring of the XSD attributes.  I’ll assume this is all quite clear – otherwise leave a comment.

 

Finally we have the rendering engine – an ITaskGenerator.

 

namespace GenTaskLib

{

      public interface ITaskGenerator

      {

            void Generate(ITask tf, TextWriter outStream);

      }

}

 

Pretty straight forward.

 

The last thing for today is the loading of the input XML.  Since we have an XSD we can use xsd.exe to generate a class for XML serialization.  This generated 3 classes and an enum.

 

The classes are Tasks, TasksTask, and TasksTaskProperty.

 

The enum is PropertyType.

 

I encourage you to copy the XSD file into a file named “GenTask.xsd” and run:

 

xsd.exe /c GenTask.xsd

 

Tomorrow: Implementing the ITask interface,