What Im trying to do is create a provided type that calls its base constructor like this in C#:
public class SubclassController : BaseClass
{
public SubclassController (IntPtr handle) : base (handle)
{}
}
The closest I can currently get is this:
public sealed class SubclassController : BaseClass
{
public SubclassController (IntPtr handle)
{
this;
base..ctor (handle);
}
Which although having the same functionality is not entirely the same.
The code I am using to build the ProvidedConstructor is as follows:
let providedConstructor = ProvidedConstructor([ProvidedParameter("handle", typeof<IntPtr>)])
let ctorInfo = typeof<SubclassController>.GetConstructor(BindingFlags.Public ||| BindingFlags.Instance, null, [|typeof<IntPtr>|], null)
providedConstructor.BaseConstructorCall <- fun args -> ctorInfo, args
providedConstructor.InvokeCode <- fun args -> <@@ () @@>
It was actually a bug in ProvidedTypes.fs which has now been fixed in the latest version. It is available from the usual place at codeplex thanks to @desco
So this code is actually all thats needed for a correctly formed base constructor call:
let providedConstructor = ProvidedConstructor([ProvidedParameter("handle", typeof<IntPtr>)])
let ctorInfo = typeof<SubclassController>.GetConstructor(BindingFlags.Public ||| BindingFlags.Instance, null, [|typeof<IntPtr>|], null)
providedConstructor.BaseConstructorCall <- fun args -> ctorInfo, args
providedConstructor.InvokeCode <- fun args -> <@@ () @@>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With