I’ve seen many examples of this tool which abstracts away the cumbersome syntax of Reflection. However none demonstrate instantiation of an unknown type. Is it safe to assume this isn’t possible with “dynamic”?
I’ve seen many examples of this tool which abstracts away the cumbersome syntax of
Share
Logically, it’s impossible to instantiate an unknown type — to instantiate a type, something must know what it is.
dynamicis useful for manipulating values of an unknown type (by assuming that it is capable of certain operations, which will fail at runtime if they are in fact not possible). To instantiate any type, however, you either need to use compile-time instantiation (e.g. using a C# constructor call), or else you need an instance ofTypethat corresponds to your desired type.