Activator.CreateInstance with private sealed class

后端 未结 4 2370
野性不改
野性不改 2020-12-17 17:30

I\'m trying to new up a LocalCommand instance which is a private class of System.Data.SqlClient.SqlCommandSet. I seem to be able to grab the type information just fine:

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-17 17:44

    My first thought would be to get the ConstructorInfo using ConstructorInfo constructorInfo = Type.GetConstructor(), and then constructorInfo.Invoke() that. I suspect that Activator.CreateInstance makes it hard to call constructors you wouldn't normally have access to, although I don't remember trying it myself.

提交回复
热议问题