I\'m trying to use reflection (ultimately on unknown at compile time) object
which include struct
. I\'ve got as far as TypedReference.MakeTypedRe
Frankly, there's no need whatsoever for TypedReference
here - just a boxed struct should work fine:
var amountField = obj.GetType().GetField("Amount");
object money = amountField.GetValue(obj);
var codeField = money.GetType().GetField("Code");
codeField.SetValue(money, "XXX");
amountField.SetValue(obj, money);
However! I will advise you of a few things: