Type type = entity.GetType();
PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance);
foreach (var p in properties)
{
if(p.Name == "State")
{
context.Entry(INSTANCE_TO_WHICH_THE_PROPERTY_p_BELONGS_TO).State = FunctionThatWillSetTheState(p.State)
}
}
具有通用签名的方法接收类“实体”的实例
public static void EntityAction<TEntity>(TEntity entity)
where TEntity : class, IObjectWithState
然后循环遍历该实例中的属性
我如何获得属性“p”所属的类的对象/实例?
因为我需要告诉这个函数
context.Entry(INSTANCE_TO_WHICH_THE_PROPERTY_p_BELONGS_TO).State = FunctionThatWillSetTheState(p.State)
谢谢。