Wiki
Clone wikiTraceabilityV2 / TraceCodeGenLib / TraceClassGenerator
#TraceClassGenerator
This class takes in a type and generates a trace class version of it. Each member will be wrapped in with tracing added. The default name of the generated class will be the name of the functional class, with a prefix of "Trace" prepended to it.
The Trace Class Generator implements all parts of IClassGenerator
###public TraceClassGenerator(Type classType, string name_space, string className = null) Constructs a TraceClassGenerator that can be used to generate a trace version for a functional class.
####classType This is the functional class that wil be used as the base for the trace class.
####name_space This parameter provides the namespace the generated trace class will inhabit.
####className Optional value. This will override the automatically generated class name and filename.
####skipMap
Optional. If a SkipMap is passed in, then all properties and methods that intersect with classType
will be not be traced.
###public TraceClassGenerator(string typeName, string name_space, string traceName = null, SkipMap skipMap = null)
####typeName The qualified name of the functional class that wil be used as the base for the trace class.
####name_space This parameter provides the namespace the generated trace class will inhabit.
####className Optional value. This will override the automatically generated class name and filename.
####skipMap
Optional. If a SkipMap is passed in, then all properties and methods that intersect with typeName
will be not be traced.
##Example:
namespace Functional.Entities
{
public class Example
{
public Example() { ... }
public Example(int i) { ... }
public Example(string s) { ... }
public virtual string Data { get; set; }
public virtual void Method1()
{ ... }
public virtual string Method2(string s)
{ ... }
}
}
We create our code generator and write the results to a file:
var codeGen = new TraceClassGenerator(typeof(Example), "Traceable.Entities");
var fileWriter = new FileWriter();
fileWriter.CreateFile(codeGen);
The following code will be written to {SolutionDir}/Traceable/Entities/TraceExample.cs
using Traceability;
namespace Traceable.Entities
{
public class TraceExample : Functional.Entities.Example
{
public TraceExample(ITracer tracer)
{ _tracer = tracer; }
public TraceExample(ITracer tracer, int i)
:base(i)
{ _tracer = tracer; }
public TraceExample(ITracer tracer, string s)
:base(s)
{ _tracer = tracer; }
public override string StringProperty
{
get { return _tracer.GetProperty("Example.Data", base.Data); }
set { base.Data = _tracer.SetProperty("Example.Data", value); }
}
public override void Method1()
{
_tracer.FunctionStart("Example.Method1");
base.Method1();
_tracer.FunctionEnd();
}
public override string Method(string s)
{
_tracer.FunctionStart("Example.Method1");
_tracer.Paramter("s", s);
var results = base.Method1(s);
return _tracer.FunctionEnd(result);
}
private readonly ITracer _tracer;
}
}
Updated