public ReflectEntity(int ObjectID) { Dictionary <string, string> Parameters = new Dictionary <string, string>(); Parameters.Add("ID", ObjectID.ToString()); object Instance = Engine.GetSingleByParameters(this.GetType(), Parameters); foreach (System.Reflection.PropertyInfo SystemAttribute in this.GetType().GetProperties()) { try { SystemAttribute.SetValue(this, Instance.GetType().GetProperty(SystemAttribute.Name).GetValue(Instance)); } catch (Exception) { } } }
public static List <object> ObjectsByDataSet(System.Type SystemType, DataSet Result) { if (Result.Tables.Count == 0) { return(new List <object>()); } if (Result.Tables[0].Rows.Count == 0) { return(new List <object>()); } List <object> ObjectList = new List <object>(); foreach (System.Data.DataRow DataRow in Result.Tables[0].Rows) { object Instance = Activator.CreateInstance(SystemType); foreach (System.Reflection.PropertyInfo SystemAttribute in SystemType.GetProperties()) { if (Attribute.IsDefined(SystemAttribute, typeof(NoDataAttribute))) { continue; } try { if (SystemAttribute.PropertyType.IsEnum) { SystemAttribute.SetValue(Instance, Enum.Parse(SystemAttribute.PropertyType, (IsCryptable(SystemAttribute) ? DecryptColumnValue(DataRow[EncryptColumnName(SystemAttribute.Name)].ToString()) : DataRow[EncryptColumnName(SystemAttribute.Name)]).ToString(), true), null); } else if (SystemAttribute.PropertyType == typeof(Guid)) { SystemAttribute.SetValue(Instance, Guid.Parse((IsCryptable(SystemAttribute) ? DecryptColumnValue(DataRow[EncryptColumnName(SystemAttribute.Name)].ToString()) : DataRow[EncryptColumnName(SystemAttribute.Name)]).ToString()), null); } else if (Attribute.IsDefined(SystemAttribute, typeof(RelationAttribute))) { object RelatedInstance = Activator.CreateInstance(SystemAttribute.PropertyType); foreach (System.Reflection.PropertyInfo RelatedAttribute in SystemAttribute.PropertyType.GetProperties()) { if (Attribute.IsDefined(RelatedAttribute, typeof(NoDataAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(RelationAttribute)) || Attribute.IsDefined(RelatedAttribute, typeof(NoRelationAttribute))) { continue; } RelatedAttribute.SetValue(RelatedInstance, (IsCryptable(RelatedAttribute) ? DecryptColumnValue(DataRow[EncryptColumnName(SystemAttribute.Name + "." + RelatedAttribute.Name)].ToString()) : DataRow[EncryptColumnName(SystemAttribute.Name + "." + RelatedAttribute.Name)]), null); } SystemAttribute.SetValue(Instance, RelatedInstance); } else { SystemAttribute.SetValue(Instance, (IsCryptable(SystemAttribute) ? DecryptColumnValue(DataRow[EncryptColumnName(SystemAttribute.Name)].ToString()) : DataRow[EncryptColumnName(SystemAttribute.Name)]), null); } } catch (Exception) { } } ObjectList.Add(Instance); } return(ObjectList); }