Esempio n. 1
0
                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)));
                        }
                    }
                }
Esempio n. 2
0
                    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));
                            }
                        }
                    }