how to getValue of property class with this method?
public static int SQLInsert<TEntity>(TEntity obj) where TEntity : class
{
foreach (var item in obj.GetType().GetProperties())
{
//item.GetValue(?,null);
}
return 1;
}
item will be a PropertyInfo. You'd use:
object value = item.GetValue(obj, null);
Note that you're pretty much ignoring the TEntity type parameter at the moment. You may want to use:
foreach (var property in typeof(TEntity).GetProperties())
That way if someone calls
SQLInsert<Customer>(customer)
and the value of customer actually refers to a subclass of Customer with extra properties, only the properties of Customer will be used.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With