!Transformation Filters

A transformation filter is a class that implements the ITransformFilter interface.

It is registered by adding an entry in the app.config file under filters.

The following is the definition of ITransformFilter:

public interface ITransformFilter
{
bool BeforeTransform(XmlDocument model, XmlDocument xslt, string outputFilename, Hashtable data, params string[] arguments);

MemoryStream AfterTransform(XmlDocument model, XmlDocument xslt, MemoryStream priorOutput, MemoryStream output, string outputFilename, Hashtable data, params string[] arguments);
}

BeforeTransform is used to prevent the transformation taking place.
If any registered filter returns false from the BeforeTransform then the output will not be written.
This allows specific files to be protected (effectively they can become write once)
It is passed:
  • the model file (as xml),
  • the transform file (as xml)
  • the name of the file to be created
  • A hashtable (intended to allow the filters to communicate with one another)
  • the command line parameters initially passed in

If it returns true then the filter permits the code generation to continue,

AfterTransform is used to alter the output. It can do anything to the output.
If it does not return null then the returned memorystream is used in place of the output.
It is passed:
  • the model file (as xml),
  • the transform file (as xml)
  • the previous output as a memorystream (or null if it did not previously exist).
  • the current output.
  • A hashtable (intended to allow the filters to communicate with one another)
  • the command line parameters initially passed in

If it returns a non-null memory stream then this is used in place of the current memory stream.

The minimal null transform would return true from the BeforeTransform and null from the AfterTransform.

Last edited Aug 20, 2008 at 8:54 PM by chriseyre2000, version 2

Comments

No comments yet.