internal static CsvMapToColumns FindInMember(MemberInfo member) { CsvMapToColumns csvMapToColumns = null; object[] attributes = member.GetCustomAttributes(typeof(CsvMapToColumns), false); if (attributes != null && attributes.Length > 0) { if (attributes.Length > 1) { throw new Exception(string.Format("Multiple {0} attributes assigned to propery: {1}", typeof(CsvMapToColumns).Name, member.Name)); } if (member.MemberType.Equals(typeof(KeyValuePair <string, object>))) { throw new Exception(string.Format("{0} attribute assigned to propery {1} must be of type: KeyValuePair<string, object>", typeof(CsvMapToColumns).Name, member.Name)); } csvMapToColumns = attributes[0] as CsvMapToColumns; } return(csvMapToColumns); }
public IEnumerator <KeyValuePair <string, object> > GetEnumerator() { foreach (FieldInfo field in csvColumns.Fields) { CsvMapToColumns csvMapToColumns = CsvMapToColumns.FindInMember(field); if (csvMapToColumns != null) { IEnumerable <KeyValuePair <string, object> > columnValue = new KeyValueEnumerator( field, obj != null ? (field.GetValue(obj) as IEnumerable <KeyValuePair <string, object> >) : null); foreach (KeyValuePair <string, object> keyValue in columnValue) { yield return(keyValue); } } else { yield return(new KeyValuePair <string, object>( field.Name, (obj != null ? field.GetValue(obj) : null))); } } foreach (PropertyInfo property in csvColumns.Properties) { if (!property.CanWrite || CsvIgnore.HasAttribute(property)) { continue; } CsvMapToColumns csvMapToColumns = CsvMapToColumns.FindInMember(property); if (csvMapToColumns != null) { IEnumerable <KeyValuePair <string, object> > columnValue = new KeyValueEnumerator( property, obj != null ? (property.GetValue(obj, null) as IEnumerable <KeyValuePair <string, object> >) : null); foreach (KeyValuePair <string, object> keyValue in columnValue) { yield return(keyValue); } } else { yield return(new KeyValuePair <string, object>( property.Name, (obj != null ? property.GetValue(obj, null) : null))); } } }
public IEnumerator <KeyValuePair <string, object> > GetEnumerator() { CsvMapToColumns csvMapToColumns = CsvMapToColumns.FindInMember(memberInfo); if (csvMapToColumns != null) { IEnumerator <KeyValuePair <string, object> > enumerator = null; if (collection != null) { enumerator = collection.GetEnumerator(); } for (int index = 0; index < LogEntry.MaxAttributes; ++index) { // If there is no enumerator for data, return null values since the header creation // doesn't need the values, just the names. string name = null; object value = null; if (enumerator != null) { if (enumerator.MoveNext()) { // Get the context attribute name/value name = enumerator.Current.Key; value = enumerator.Current.Value; } else { // If no attributes exist for all slots, use empty strings to // ensure the commas are added to the csv. name = ""; value = ""; } } yield return(new KeyValuePair <string, object>( String.Format("{0}Name{1}", csvMapToColumns.AlternateName, (index + 1)), name)); yield return(new KeyValuePair <string, object>( String.Format("{0}Value{1}", csvMapToColumns.AlternateName, (index + 1)), value)); } } }