未经测试,但也许这样可以工作:
string modelProperty = "Some Property Name";string value = "Some Value";var property = entity.GetType().GetProperty(modelProperty);if (property != null){ Type t = Nullable.GetUnderlyingType(property.PropertyType) ?? property.PropertyType; object safevalue = (value == null) ? null : Convert.ChangeType(value, t); property.SetValue(entity, safevalue, null);}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)