P
Philipp Schumann
Hi,
Using Type.GetConstructors(BindingFlags), I can't seem to be able to acquire
a ConstructorInfo object for the implicit, parameter-less constructor for a
struct if it doesn't define an explicit constructor with parameters itself.
The same apparently works for classes, though - if a class doesn't specify
any instance constructors explicitly, an implicit, public, parameterless
instance constructor is assumed and the appropriate ConstructorInfo is
returned.
Since it is possible to create a new instance of a struct that doesn't have
explicit constructors defined in code, the same should be possible using
Reflection, but what am I supposed to do without the appropriate
ConstructorInfo object?
I am aware that structs, being value types, cannot be a null reference and
thus simply declaring them will actually create them in memory, with the
"constructor" construct simply existing to provide a convenient
initialization mechanism, so this is probably why. But how would I do this
dynamically, using Reflection, just with the Type instance that's telling me
that IsValueType=true?
Cheers,
Phil
Using Type.GetConstructors(BindingFlags), I can't seem to be able to acquire
a ConstructorInfo object for the implicit, parameter-less constructor for a
struct if it doesn't define an explicit constructor with parameters itself.
The same apparently works for classes, though - if a class doesn't specify
any instance constructors explicitly, an implicit, public, parameterless
instance constructor is assumed and the appropriate ConstructorInfo is
returned.
Since it is possible to create a new instance of a struct that doesn't have
explicit constructors defined in code, the same should be possible using
Reflection, but what am I supposed to do without the appropriate
ConstructorInfo object?
I am aware that structs, being value types, cannot be a null reference and
thus simply declaring them will actually create them in memory, with the
"constructor" construct simply existing to provide a convenient
initialization mechanism, so this is probably why. But how would I do this
dynamically, using Reflection, just with the Type instance that's telling me
that IsValueType=true?
Cheers,
Phil