I am working with an MSBuild task that is supposed to instantiate a class. Initially, the class had only one constructor without parameters, therefore, to complete the entire MSBuild task, there was a type name for instantiating the class. Now we have a precedent for launching a task for specific designers, and I do not know how to deal with this in a general way. Let's say I need to create different variants of ClassA :
public class ClassA { public ClassA() { } public ClassA(int someArgument) { } public ClassA(int someArgument, bool someOtherArgument) { } }
Here's what the original task looked like:
<DoSomethingTask Assembly="ContainsClassA.dll" Type="ClassA" />
My ideal task would look something like this so that I could call any constructor with primitive types as arguments:
<DoSomethingTask Assembly="ContainsClassA.dll" Type="ClassA"> <ConstructorArgs> <Arg type="int">1</Arg> <Arg type="bool">True</Arg> </ConstructorArgs> </DoSomethingTask>
I really lost what to look for to get this type of functionality. I could do something like create a string property ConstructorArgs and parse it in whatever format I want, but I hope something cleaner exists. Thanks for any help you can provide!
Change In case someone wonders, the actual task I am trying to modify creates a pre-generated view based on an instance of the Entity Framework DbContext. We have our own subclass of DbContext with various constructors, and we would like to be able to call a specific one when generating a view.
source share