I got this code that works (simplified) :
Assembly lib = Assembly.LoadFile("C:\\mydll.dll");
var libType = lib.GetTypes();
Type mvType = libType[0];
PropertyInfo WidthProperty = mvType.GetProperty("Width");
But then, I’d like to access to the default value with a code like
var WidthPropertyValue = WidthProperty.GetValue(???, null);
The thing is that we CAN’T instantiate the object with Activator.CreateInstance cause the constructor need that the whole huge project is loaded to work… anyway, that’s not the point about working around that problem.
The thing is that, is it possible to access to the default way with this strategy ?
Is it possible with another way ?
completely impossible ?
If the assembly code is accessible I would recommend defining default values with an
Attribute.Otherwise I don’t think its possible. Property default values are not part of an assembly’s metadata (default value concept does not exist as such, that is why
DefaultValueAttributeexists) so I’m not sure you can figure it out short of creating an instance of the object. It could be anything: default value of the backing field, some value set in the constructor, it could be based on some environment condition, etc.UPDATE: I’ve seen a few answers/comments pointing to creating the default type of the property’s type. Property default values are implementation specific, not type specific. They might coincide in many cases but it doesn’t have to be so.