- public static T DataRowToEntity<T>(DataRow SrcRow) where T : BaseEntity
- {
- var InstType = typeof(T);
- var Inst = System.Activator.CreateInstance(InstType);
- var BdFlag = BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance;
- // X 表示实例的属性,X1表示属性名
- var PropInfoArray = from X in InstType.GetProperties(BdFlag)
- where X.CanWrite
- let X1 = X.Name
- where SrcRow.Table.Columns.Contains(X1)
- select new
- {
- Prop = X,
- PropName = X1
- };
- foreach (var PropInfo in PropInfoArray)
- {
- var PropValue = SrcRow[PropInfo.PropName];
- PropValue = PropValue.IsNullEx() ? null : PropValue;
- PropInfo.Prop.SetValue(Inst, PropValue, null);
- }
- return (T)Inst;
- }
复制代码 不太明白 为什么方法后面写一个 where T:BaseEntity
说继承这个接口,可是这个方法是BaseEntity这个类里面的 |