Created
March 5, 2014 11:40
-
-
Save regme/9365635 to your computer and use it in GitHub Desktop.
Dynamic SetProperty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void SetValue(dynamic target, string propname, object val ){ | |
var argInfo = new List<CSharpArgumentInfo>{ | |
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), | |
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) | |
}; | |
var binder = Binder.SetMember( | |
CSharpBinderFlags.None, | |
propname, | |
this.GetType(), | |
argInfo | |
); | |
var callsite = CallSite<Func<CallSite, object, object, object>>.Create(binder); | |
callsite.Target(callsite, target, val); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment