//--------------------------------------------------------------------------------------------- public void FillFromDataRow(DataRow row) { foreach (PropertyInfo pInfo in this.GetType().GetProperties()) { ParameterAttribute attrParam = (ParameterAttribute)this.GetAttribute(pInfo, typeof(ParameterAttribute)); if (attrParam != null) { Usages defaultUsage = Usages.Add | Usages.Load | Usages.Save; UsageAttribute usage = (UsageAttribute)this.GetAttribute(pInfo, typeof(UsageAttribute)); if (usage != null) { defaultUsage = usage.Usage; } if ((defaultUsage & Usages.Load) == Usages.Load) { object value = (row.Table.Columns.Contains(attrParam.Name)) ? Utils.DBNullToNull(row[attrParam.Name]) : null; if (pInfo.PropertyType.GetInterface("Caleb.Library.CAL.ICalBusiness") != null) { ICalBusiness business = (ICalBusiness)pInfo.GetValue(this, null); business.ID = CalBusiness.ToID(value); } else { pInfo.SetValue(this, value, null); } } } } }
//--------------------------------------------------------------------------------------------- public DataRow FillToDataRow(DataRow row) { foreach (PropertyInfo pInfo in this.GetType().GetProperties()) { ParameterAttribute attrParam = (ParameterAttribute)this.GetAttribute(pInfo, typeof(ParameterAttribute)); if (attrParam != null) { Usages defaultUsage = Usages.Add | Usages.Save | Usages.Load; UsageAttribute usage = (UsageAttribute)this.GetAttribute(pInfo, typeof(UsageAttribute)); if (usage != null) { defaultUsage = usage.Usage; } if ((defaultUsage & Usages.Add) == Usages.Add) { bool isBusiness = pInfo.PropertyType.GetInterface("Caleb.Library.CAL.ICalBusiness") != null; Type type = pInfo.PropertyType; bool isGenericNullable = pInfo.PropertyType.IsGenericType && pInfo.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>); type = isGenericNullable ? Nullable.GetUnderlyingType(pInfo.PropertyType) : pInfo.PropertyType; if (isBusiness) { type = typeof(Int32); } if (!row.Table.Columns.Contains(attrParam.Name)) { row.Table.Columns.Add(attrParam.Name, type); } if (isBusiness) { ICalBusiness business = (ICalBusiness)pInfo.GetValue(this, null); row[attrParam.Name] = Utils.ToDBDataNullValue(business.ID); } else { row[attrParam.Name] = Utils.ToDBDataNullValue(pInfo.GetValue(this, null)); } } } } return(row); }