Wiki
Clone wikiTraceabilityV2 / TraceCodeGenLib / TraceFactoryGenerator
#TraceFactoryGenerator
The TraceFactoryGenerator creates a trace version of functional factory. The resulting trace factory will then construct trace versions of the class constructed by the functional factory.
###public TraceFactoryGenerator(Type functionalFactory, Type traceClass, string name_space, string factoryName = null, SkipMap skipMap = null) Constructs a TraceFactoryGenerator that can be used to generate factories for trace classes.
####functionalFactory The functional factory type that the resulting trace factory will be based on.
####traceClass The trace class that will be returned by the trace factory.
####name_space This parameter provides the namespace the generated factory will inhabit.
####factoryName Optional: if this is used, it will override the class name in the generated code, as well as the filename used to write the code to disk.
####skipMap
Optional value. If a SkipMap is passed in, then all properties and methods that intersect with functionalFactory
will be not be traced.
###public TraceFactoryGenerator(string typeName, string traceClass, string name_space, string factoryName = null, SkipMap skipMap = null)
####typeName The qualified name of the functional factory type that the resulting trace factory will be based on.
####traceClass The qualified name of the trace class that will be returned by the trace factory.
####name_space This parameter provides the namespace the generated factory will inhabit.
####factoryName Optional: if this is used, it will override the class name in the generated code, as well as the filename used to write the code to disk.
####skipMap
Optional value. If a SkipMap is passed in, then all properties and methods that intersect with typeName
will be not be traced.
###public TraceFactoryGenerator(FactoryGenerator factory, TraceClassGenerator traceClass, string name_space, string factoryName = null, SkipMap skipMap = null)
####factory An instance of the FactoryGenerator which was used to generate the functional factory that the resulting trace factory will be based on.
####traceClass An instance of the TraceClassGenerator which was used to generate the trace class that will be returned by the trace factory.
####name_space This parameter provides the namespace the generated factory will inhabit.
####factoryName Optional: if this is used, it will override the class name in the generated code, as well as the filename used to write the code to disk.
####skipMap
Optional value. If a SkipMap is passed in, then all properties and methods that intersect with factory
will be not be traced.
##Example:
namespace Functional.Factories
{
public class ExampleFactory
{
public virtual Example Construct()
{ return new Example(); }
public virtual Example Construct(int i)
{ return new Example(i); }
public virtual Example Construct(string s)
{ return new Example(s); }
}
}
namespace Traceable.Entities
{
public class TraceExample : Functional.Entities.Example
{
public TraceExample(ITracer tracer) { ... }
public TraceExample(ITracer tracer, int i) { ... }
public TraceExample(ITracer tracer, string s) { ... }
...
}
}
We create our code generator and write the results to a file:
var codeGen = new TraceFactoryGenerator(typeof(ExampleFactory),
typeof(TraceExample), "Traceable.Factories");
var fileWriter = new FileWriter();
fileWriter.CreateFile(codeGen);
The following code will be written to {SolutionDir}/Traceable/Factories/TraceExampleFactory.cs
using Traceability;
namespace Traceable.Factories
{
public class TraceExampleFactory
public TraceExampleFactory(Itracer tracer)
{ _tracer = tracer; }
public virtual Example Construct()
{
return new TraceExample(_tracer);
}
public virtual Example Construct(int i)
{
return new TraceExample(_tracer, i);
}
public virtual Example Construct(string s)
{
return new TraceExample(_tracer, s);
}
private readonly ITracer _tracer;
}
}
##Example Two We can create all three classes with this code:
var fileWriter = new FileWriter();
var factory = new FactoryGenerator(typeof(Example), "Functional.Factories");
fileWriter.CreateFile(factory);
var trace = new TraceClassGenerator(typeof(Example), "Traceable.Entities");
fileWriter.CreateFile(trace);
var traceFactory = new TraceFactoryGenerator(factory, trace, "Traceable.Factories");
fileWriter.CreateFile(traceFactory);
Updated