My app uses reflection to analyze c++/cli code in runtime.
I need to determine if a type has a constructor without unmanaged parameters (pointers and such), because i want later on to use:
ConstructorInfo constructorInfo;
// ...
var ret = constructorInfo.Invoke(BindingFlags..., null, myParameters, null);
if the constructor has a pointer to an unmanaged object as a parameter, there is a casting exception when i pass null to it.
So i how do i determine that? there is no IsManaged... and IsPointer does not help in this case.
It's not clear what your problem actually is, but here is a short demonstration program that shows passing null
to a constructor that takes a pointer as an argument and detects it with IsPointer
:
using System;
using System.Reflection;
namespace pointers
{
unsafe class Program
{
public Program(int* x)
{
Console.WriteLine("It worked!");
}
static void Main(string[] args)
{
ConstructorInfo[] c = typeof(Program).GetConstructors();
c[0].Invoke(BindingFlags.Default, null, new object[] { null }, null);
Console.WriteLine(c[0].GetParameters()[0].ParameterType.IsPointer);
}
}
}
It prints:
It worked! True
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