(E-Mail Removed)am <(E-Mail Removed)> wrote:
> here is the simplified code: the myCor is set to null when run the program.
> but if remove the "ref" from the constructor's parameter, myCor gets a valid
> value.
As Markus said, it's very rare to need "ref" in a constructor (and I'd
need to see a good example to persuade me that it's a good idea) but
you can make GetConstructor work. Here's a short but complete example:
using System;
using System.Reflection;
public class MyClass
{
public MyClass(ref object obj)
{
Console.WriteLine ("Called");
}
}
class Test
{
static void Main()
{
Type type = typeof(MyClass);
Type[] parameterTypes = new Type[]
{ typeof(object).MakeByRefType() };
ConstructorInfo constructor = type.GetConstructor
(parameterTypes);
object[] args = new object[1];
constructor.Invoke(args);
}
}
--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog:
http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too