cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
mikegru
Level 4

Custom Action: Managed Code

Is it possible to set up a custom action that calls a managed assembly with a class that has an overridden constructor? It looks like it just assumes a default even if a default doesn't exist. For example:

public class TestClass
{
public TestClass()
{
}

public TestClass(string stringTest, bool boolTest, int iTest)
{
}

public void ShowMessage(string stringMessage)
{
Console.WriteLine("Testing 1...2...3");
}
}

When I create the custom action, I don't see a way to use the overridden ctor. When I remove the default, I still don't see the parameters for the only ctor left.
Labels (1)
0 Kudos
(2) Replies
Christopher_Pai
Level 16

I would reccomend that you use WiX DTF with InstallShield instead. The custom action will be a static class with a static method:

//Example
[CustomAction]
ActionResult MyCustomAction( Session session )
{
var productName = session["ProductName"];
}


Use this as a adapter for your private class and do whatever intefaces, overloads that you deem needed.

I have lots of examples on my blog.
0 Kudos
MichaelU
Level 12 Flexeran
Level 12 Flexeran

The core of Christopher's recommendation holds with either technology. If you want to use a custom constructor, you must put that code on something that does not require a custom constructor to access. This can be a static method, or a method on a class with a parameterless constructor.

If you want full flexibility, you could theoretically create a static method with parameters for both the constructor and the method it eventually calls into.

public static void CTorWrapper(string ctor1, bool ctor2, int ctor3, string meth1)
{
new TestClass(ctor1, ctor2, ctor3).ShowMessage(meth1);
}
0 Kudos