Is there any way to build a generic type like this?
Type underlyingType = propertyInfo.PropertyType;
Type genericType = typeof(Action<underlyingType>);
I know it may not be possible. so to get workarounds : I want to create a delegate Action<T> for setter of some properties.
var type = propertyInfo.PropertyType;
var defaultVal = type.IsValueType ? Activator.CreateInstance(type) : null;
var setter = (Action<object>)propertyInfo
.GetSetMethod(true)
.CreateDelegate(typeof(Action<object>), this);
var resetter = new Action(() => setter(defaultVal));
return resetter;
This does not work. because I have to pass exact matching type. If Property setter takes double I have to pass Action<double> then it works.
I have Generic container type and Underlying Type in hand. how can I mix them?
Note that I'm working on group of properties taken from a class. not a single property.
var props = GetType().GetProperties(Flags);