private void UpdateComplexField(IComplexField complexField, string data) { string[] fields = data.Split(CurrentSeperators.ComponentDataElement); foreach (PropertyInfo p in complexField.GetType().GetProperties()) { PositionIndexAttribute pos = p.GetCustomAttributes().Where(a => a is PositionIndexAttribute).FirstOrDefault() as PositionIndexAttribute; if (pos != null && pos.Index < fields.Length) { p.SetValue(complexField, fields[pos.Index]); } } }
private SegmentBase ParseUsingPosition(Type type, string[] fields) { SegmentBase ret = Activator.CreateInstance(type) as SegmentBase; foreach (PropertyInfo p in ret.GetType().GetProperties()) { PositionIndexAttribute pos = p.GetCustomAttributes().Where(a => a is PositionIndexAttribute).FirstOrDefault() as PositionIndexAttribute; if (pos != null && pos.Index < fields.Length) { if (p.PropertyType.GetInterfaces().Contains(typeof(IComplexField))) { IComplexField complexField = Activator.CreateInstance(p.PropertyType) as IComplexField; this.UpdateComplexField(complexField, fields[pos.Index]); p.SetValue(ret, complexField); } else { p.SetValue(ret, fields[pos.Index]); } } } return(ret); }