I started working in T4 and got along well at first, but then I came across a problem that is actually quite obvious and may not be solvable, but maybe there is a way that I just do not have enough experience to know or see.
Given the following class:
public class T4Test : CodeActivity { protected override void Execute(CodeActivityContext context) { } [Input("InX")] public InArgument<string> InX { get; set; } [Output("OutX")] public OutArgument<string> OutX { get; set; } }
I want this as a conclusion:
public class ActivityWrapper { private readonly T4Test _activity; private readonly ActivityContext _context; public ActivityWrapper(T4Test activity, ActivityContext context) { this._activity = activity; this._context = context; } public string InX { get { return this._activity.InX.Get(this._context); } } public string OutX { get { return this._activity.OutX.Get(this._context); } set { this._activity.OutX.Set(this._context, value); } } }
I calculated the Reflection material that I need, and I know how the T4 code looks, but there is one problem: I need it in the same project as the T4Test class. However, in order to load the assembly and reflect it, it needs to be compiled, but of course it is a bit complicated if I intend to change the same assembly code. (And I think NCrunch is not simplifying things.)
Now all I hope can still solve this:
- The project will be compiled without a generated class. This is because the class will implement interfaces that will be automatically registered / enabled by the IoC container. In any case, this is also impossible to verify, because the
ActivityContext cannot be mocked. - For this reason, he should not be there or correct all the time. I just need to say “generate this now” before delivering the DLL.
- For the same reason, I also don’t care if the T4 template is actually in the project - as long as the generated file gets into the project (although without the need for another project for the template and creating PostBuild events for copying
.cs ). - To be precise, you don’t even have to be T4. If there are other possible ways to do this, I will be happy to use this as well.
Is there any way to achieve this? (And was it clear enough?)
source share