public ChoCSVWriter <T> WithFieldForType <TClass>(Expression <Func <TClass, object> > field, int?position, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null, Func <object, object> valueConverter = null, Func <dynamic, object> valueSelector = null, Func <string> headerSelector = null, object defaultValue = null, object fallbackValue = null, string formatText = null, string nullValue = null, bool excelField = false) where TClass : class { if (field == null) { return(this); } return(WithField(field.GetMemberName(), position, field.GetPropertyType(), quoteField, fillChar, fieldValueJustification, truncate, fieldName, valueConverter, valueSelector, headerSelector, defaultValue, fallbackValue, field.GetFullyQualifiedMemberName(), formatText, nullValue, excelField, field.GetReflectedType())); }
private ChoFieldValueJustification GetFieldValueJustification(ChoFieldValueJustification? fieldValueJustification, Type fieldType) { if (fieldValueJustification != null) return fieldValueJustification.Value; if (fieldType == typeof(int) || fieldType == typeof(uint) || fieldType == typeof(long) || fieldType == typeof(ulong) || fieldType == typeof(short) || fieldType == typeof(ushort) || fieldType == typeof(byte) || fieldType == typeof(sbyte) || fieldType == typeof(float) || fieldType == typeof(double) || fieldType == typeof(decimal) ) { return ChoFieldValueJustification.Right; } else return ChoFieldValueJustification.Left; }
private ChoCSVWriter <T> WithField(string name, Type fieldType = null, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool?truncate = null, string fieldName = null, int?fieldPosition = null, Func <object, object> valueConverter = null, Func <dynamic, object> valueSelector = null, Func <string> headerSelector = null, object defaultValue = null, object fallbackValue = null, string fullyQualifiedMemberName = null, string formatText = null, string nullValue = null, bool excelField = false) { if (!name.IsNullOrEmpty()) { if (!_clearFields) { ClearFields(); Configuration.MapRecordFields(Configuration.RecordType); } if (fieldName.IsNullOrWhiteSpace()) { fieldName = name; } string fnTrim = name.NTrim(); ChoCSVRecordFieldConfiguration fc = null; PropertyDescriptor pd = null; //if (Configuration.CSVRecordFieldConfigurations.Any(o => o.Name == fnTrim)) //{ if (fullyQualifiedMemberName != null) { fc = Configuration.CSVRecordFieldConfigurations.Where(o => o.DeclaringMember == fullyQualifiedMemberName).FirstOrDefault(); } else { fc = Configuration.CSVRecordFieldConfigurations.Where(o => o.Name == fnTrim).FirstOrDefault(); } if (fc != null && fieldPosition == null) { fieldPosition = fc.FieldPosition; } //Configuration.CSVRecordFieldConfigurations.Remove(fc); //} if (fc == null) { pd = ChoTypeDescriptor.GetNestedProperty(typeof(T), fullyQualifiedMemberName.IsNullOrWhiteSpace() ? name : fullyQualifiedMemberName); if (fieldPosition == null) { fieldPosition = Configuration.CSVRecordFieldConfigurations.Count > 0 ? Configuration.CSVRecordFieldConfigurations.Max(f => f.FieldPosition) : 0; fieldPosition++; } } ChoCSVRecordFieldConfiguration nfc = null; if (fc != null) { nfc = fc; if (fieldType != null) { nfc.FieldType = fieldType; } if (quoteField != null) { nfc.QuoteField = quoteField; } if (fillChar != null) { nfc.FillChar = fillChar; } if (fieldValueJustification != null) { nfc.FieldValueJustification = fieldValueJustification; } if (truncate != null) { nfc.Truncate = truncate.Value; } if (fieldName != null) { nfc.FieldName = fieldName; } if (valueConverter != null) { nfc.ValueConverter = valueConverter; } if (valueSelector != null) { nfc.ValueSelector = valueSelector; } if (headerSelector != null) { nfc.HeaderSelector = headerSelector; } if (defaultValue != null) { nfc.DefaultValue = defaultValue; } if (fallbackValue != null) { nfc.FallbackValue = fallbackValue; } if (formatText != null) { nfc.FormatText = formatText; } if (nullValue != null) { nfc.NullValue = nullValue; } nfc.ExcelField = excelField; } else { nfc = new ChoCSVRecordFieldConfiguration(fnTrim, fieldPosition.Value) { FieldType = fieldType, QuoteField = quoteField, FillChar = fillChar, FieldValueJustification = fieldValueJustification, Truncate = truncate != null ? truncate.Value : true, FieldName = fieldName, ValueConverter = valueConverter, ValueSelector = valueSelector, HeaderSelector = headerSelector, DefaultValue = defaultValue, FallbackValue = fallbackValue, FormatText = formatText, NullValue = nullValue, ExcelField = excelField }; if (fullyQualifiedMemberName.IsNullOrWhiteSpace()) { nfc.PropertyDescriptor = fc != null ? fc.PropertyDescriptor : pd; nfc.DeclaringMember = fc != null ? fc.DeclaringMember : fullyQualifiedMemberName; } else { pd = ChoTypeDescriptor.GetNestedProperty(typeof(T), fullyQualifiedMemberName); nfc.PropertyDescriptor = pd; nfc.DeclaringMember = fullyQualifiedMemberName; } if (pd != null) { if (nfc.FieldType == null) { nfc.FieldType = pd.PropertyType; } } Configuration.CSVRecordFieldConfigurations.Add(nfc); } } return(this); }
private ChoFixedLengthWriter <T> WithField(string name, int startIndex, int size, Type fieldType = null, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null, Func <object, object> valueConverter = null, Func <dynamic, object> valueSelector = null, object defaultValue = null, object fallbackValue = null, string fullyQualifiedMemberName = null, string formatText = null, string nullValue = null) { if (!name.IsNullOrEmpty()) { if (!_clearFields) { ClearFields(); Configuration.MapRecordFields(Configuration.RecordType); } if (fieldName.IsNullOrWhiteSpace()) { fieldName = name; } string fnTrim = name.NTrim(); ChoFixedLengthRecordFieldConfiguration fc = null; PropertyDescriptor pd = null; if (Configuration.FixedLengthRecordFieldConfigurations.Any(o => o.Name == fnTrim)) { fc = Configuration.FixedLengthRecordFieldConfigurations.Where(o => o.Name == fnTrim).First(); Configuration.FixedLengthRecordFieldConfigurations.Remove(fc); } else { pd = ChoTypeDescriptor.GetNestedProperty(typeof(T), fullyQualifiedMemberName.IsNullOrWhiteSpace() ? name : fullyQualifiedMemberName); } var nfc = new ChoFixedLengthRecordFieldConfiguration(name.Trim(), startIndex, size) { FieldType = fieldType, QuoteField = quoteField, FillChar = fillChar, FieldValueJustification = fieldValueJustification, Truncate = truncate, FieldName = fieldName.IsNullOrWhiteSpace() ? name : fieldName, ValueConverter = valueConverter, ValueSelector = valueSelector, DefaultValue = defaultValue, FallbackValue = fallbackValue, FormatText = formatText, NullValue = nullValue }; if (fullyQualifiedMemberName.IsNullOrWhiteSpace()) { nfc.PropertyDescriptor = fc != null ? fc.PropertyDescriptor : pd; nfc.DeclaringMember = fc != null ? fc.DeclaringMember : fullyQualifiedMemberName; } else { pd = ChoTypeDescriptor.GetNestedProperty(typeof(T), fullyQualifiedMemberName); nfc.PropertyDescriptor = pd; nfc.DeclaringMember = fullyQualifiedMemberName; } if (pd != null) { if (nfc.FieldType == null) { nfc.FieldType = pd.PropertyType; } } Configuration.FixedLengthRecordFieldConfigurations.Add(nfc); } return(this); }
public ChoFixedLengthWriter <T> WithField(string name, int startIndex, int size, Type fieldType = null, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null, Func <object, object> valueConverter = null, Func <dynamic, object> valueSelector = null, object defaultValue = null, object fallbackValue = null, string formatText = null, string nullValue = null) { return(WithField(name, startIndex, size, fieldType, quoteField, fillChar, fieldValueJustification, truncate, fieldName, valueConverter, valueSelector, defaultValue, fallbackValue, null, formatText, nullValue)); }
public ChoFixedLengthWriter <T> WithField <TField>(Expression <Func <T, TField> > field, int startIndex, int size, Type fieldType = null, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null, Func <object, object> valueConverter = null, Func <dynamic, object> valueSelector = null, object defaultValue = null, object fallbackValue = null, string formatText = null, string nullValue = null) { if (field == null) { return(this); } return(WithField(field.GetMemberName(), startIndex, size, fieldType, quoteField, fillChar, fieldValueJustification, truncate, fieldName, valueConverter, valueSelector, defaultValue, fallbackValue, field.GetFullyQualifiedMemberName(), formatText, nullValue)); }
public ChoCSVRecordFieldConfigurationMap Justification(ChoFieldValueJustification?value) { _config.FieldValueJustification = value; return(this); }
private ChoFieldValueJustification GetFieldValueJustification(ChoFieldValueJustification?fieldValueJustification) { return(fieldValueJustification == null ? ChoFieldValueJustification.Left : fieldValueJustification.Value); }
private ChoFieldValueJustification GetFieldValueJustification(ChoFieldValueJustification?fieldValueJustification, Type fieldType) { return(fieldValueJustification == null ? ChoFieldValueJustification.None : fieldValueJustification.Value); }
public ChoCSVWriter <T> WithField(string name, Type fieldType = null, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null, int?fieldPosition = null, Func <object, object> valueConverter = null, object defaultValue = null, object fallbackValue = null) { if (!name.IsNullOrEmpty()) { if (!_clearFields) { Configuration.CSVRecordFieldConfigurations.Clear(); _clearFields = true; } if (fieldName.IsNullOrWhiteSpace()) { fieldName = name; } int maxFieldPos = fieldPosition == null ? (Configuration.CSVRecordFieldConfigurations.Count > 0 ? Configuration.CSVRecordFieldConfigurations.Max(f => f.FieldPosition) + 1 : 1) : fieldPosition.Value; Configuration.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration(name, maxFieldPos) { FieldType = fieldType, QuoteField = quoteField, FillChar = fillChar, FieldValueJustification = fieldValueJustification, Truncate = truncate, FieldName = fieldName, ValueConverter = valueConverter, DefaultValue = defaultValue, FallbackValue = fallbackValue }); } return(this); }
public ChoFixedLengthWriter <T> WithField(string name, int startIndex, int size, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null) { return(WithField(name, startIndex, size, null, quoteField, fillChar, fieldValueJustification, truncate, fieldName)); }
public ChoFixedLengthWriter <T> WithField(string name, int startIndex, int size, Type fieldType, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null) { if (!name.IsNullOrEmpty()) { if (!_clearFields) { Configuration.FixedLengthRecordFieldConfigurations.Clear(); _clearFields = true; } Configuration.FixedLengthRecordFieldConfigurations.Add(new ChoFixedLengthRecordFieldConfiguration(name.Trim(), startIndex, size) { FieldType = fieldType, QuoteField = quoteField, FillChar = fillChar, FieldValueJustification = fieldValueJustification, Truncate = truncate, FieldName = fieldName.IsNullOrWhiteSpace() ? name : fieldName }); } return(this); }
public ChoCSVWriter <T> WithField(string name, Type fieldType = null, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null, int?fieldPosition = null, Func <object, object> valueConverter = null, object defaultValue = null, object fallbackValue = null, string formatText = null) { return(WithField(name, fieldType, quoteField, fillChar, fieldValueJustification, truncate, fieldName, fieldPosition, valueConverter, defaultValue, fallbackValue, null, formatText)); }
public ChoCSVWriter <T> WithField <TField>(Expression <Func <T, TField> > field, Type fieldType = null, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null, int?fieldPosition = null, Func <object, object> valueConverter = null, object defaultValue = null, object fallbackValue = null, string formatText = null) { if (field == null) { return(this); } return(WithField(field.GetMemberName(), fieldType, quoteField, fillChar, fieldValueJustification, truncate, fieldName, fieldPosition, valueConverter, defaultValue, fallbackValue, field.GetFullyQualifiedMemberName(), formatText)); }
public ChoCSVWriter <T> WithField(string name, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true, string fieldName = null, int?fieldPosition = null) { return(WithField(name, null, quoteField, fillChar, fieldValueJustification, truncate, fieldName, fieldPosition)); }
public ChoCSVWriter <T> WithField(string fieldName, Type fieldType, bool?quoteField = null, char?fillChar = null, ChoFieldValueJustification?fieldValueJustification = null, bool truncate = true) { if (!fieldName.IsNullOrEmpty()) { if (!_clearFields) { Configuration.CSVRecordFieldConfigurations.Clear(); _clearFields = true; } int maxFieldPos = Configuration.CSVRecordFieldConfigurations.Count > 0 ? Configuration.CSVRecordFieldConfigurations.Max(f => f.FieldPosition) : 0; Configuration.CSVRecordFieldConfigurations.Add(new ChoCSVRecordFieldConfiguration(fieldName.Trim(), ++maxFieldPos) { FieldType = fieldType, QuoteField = quoteField, FillChar = fillChar, FieldValueJustification = fieldValueJustification, Truncate = truncate }); } return(this); }