Activator.CreateInstance - How to create instances of classes that have parameterized constructors

后端 未结 5 1753
野性不改
野性不改 2020-12-24 12:21

I have read a few bits and bobs online about this topic but found none that work for me. What I am trying to do is create a class of a runtime Type.

I use Acti

5条回答
  •  醉酒成梦
    2020-12-24 12:50

    I'm using this method to get around an issue I ran into, and it seems to be working exactly as I hoped. :)

    object instance = Activator.CreateInstance(
        typeof(OpCode),
        BindingFlags.NonPublic | BindingFlags.Instance,
        default(Binder),
        new object[] { stringname, pop, push, operand, type, size, s1, s2, ctrl, endsjmpblk, stack },
        default(CultureInfo));
    

提交回复
热议问题