Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Jul 15, 2010 08:47 AM by mtugnoli
Member
31 Points
55 Posts
Jul 15, 2010 08:47 AM|LINK
Hi,
I would like to assign values to an entity dynamically,
This is my source, but don't run ...
Anyone have a idea ?
public static void SetProperty(object obj, string sProperty, object oValue) { object[] oParam = new object[1]; oParam[0] = oValue; obj.GetType().InvokeMember(sProperty, BindingFlags.SetProperty, null, obj, oParam); } public static object GetProperty(object obj, string sProperty, object oValue) { object[] oParam = new object[1]; oParam[0] = oValue; return obj.GetType().InvokeMember(sProperty, BindingFlags.GetProperty, null, obj, oParam); }
private void test() { Product eProd = GetProductById(vId); SetProperty(eProd, "ProductName", "NewValue"); }
mtugnoli
Member
31 Points
55 Posts
InvokeMember and Entity Framework
Jul 15, 2010 08:47 AM|LINK
Hi,
I would like to assign values to an entity dynamically,
This is my source, but don't run ...
Anyone have a idea ?
public static void SetProperty(object obj, string sProperty, object oValue)
{
object[] oParam = new object[1];
oParam[0] = oValue;
obj.GetType().InvokeMember(sProperty, BindingFlags.SetProperty, null, obj, oParam);
}
public static object GetProperty(object obj, string sProperty, object oValue)
{
object[] oParam = new object[1];
oParam[0] = oValue;
return obj.GetType().InvokeMember(sProperty, BindingFlags.GetProperty, null, obj, oParam);
}
private void test()
{
Product eProd = GetProductById(vId);
SetProperty(eProd, "ProductName", "NewValue");
}