public bool Validate(ADAGEData data) { string type = data.GetType().ToString(); ADAGEEventInfo dataInfo = null; if (events != null && events.ContainsKey(type)) { dataInfo = events[type]; } else if (context != null && context.ContainsKey(type)) { dataInfo = context[type]; } if (dataInfo == null) { return(false); } FieldInfo field; PropertyInfo property; foreach (KeyValuePair <string, ADAGEDataPropertyInfo> prop in dataInfo.properties) { field = data.GetType().GetField(prop.Key); if (field != null) { if (!prop.Value.IsValid(field.GetValue(data))) { return(false); } } else { property = data.GetType().GetProperty(prop.Key); if (property == null) { return(false); //it's neither and shouldn't be here } if (!prop.Value.IsValid(property.GetValue(data, null))) { return(false); } } } return(true); }
public static ADAGEData Copy(ADAGEData data) { Type type = data.GetType(); ADAGEData newData = (ADAGEData)Activator.CreateInstance(type); foreach (PropertyInfo sourcePropertyInfo in type.GetProperties()) { PropertyInfo destPropertyInfo = type.GetProperty(sourcePropertyInfo.Name); destPropertyInfo.SetValue( newData, sourcePropertyInfo.GetValue(data, null), null); } foreach (FieldInfo sourceFieldInfo in type.GetFields()) { FieldInfo destFieldInfo = type.GetField(sourceFieldInfo.Name); destFieldInfo.SetValue( newData, sourceFieldInfo.GetValue(data)); } return(newData); }