Skip to content

Instantly share code, notes, and snippets.

@regme
Created March 5, 2014 11:40
Show Gist options
  • Save regme/9365635 to your computer and use it in GitHub Desktop.
Save regme/9365635 to your computer and use it in GitHub Desktop.
Dynamic SetProperty
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