public ChoCSVReader <T> WithField(string name, int?position, Type fieldType = null, bool?quoteField = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, object defaultValue = null, object fallbackValue = null, string altFieldNames = null, string formatText = null) { return(WithField(name, position, fieldType, quoteField, fieldValueTrimOption, fieldName, valueConverter, defaultValue, fallbackValue, altFieldNames, null, formatText)); }
public ChoCSVReader <T> WithField(string name, Type fieldType, bool?quoteField = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null) { int maxFieldPos = Configuration.CSVRecordFieldConfigurations.Count > 0 ? Configuration.CSVRecordFieldConfigurations.Max(f => f.FieldPosition) : 0; return(WithField(name, ++maxFieldPos, fieldType, quoteField, fieldValueTrimOption, fieldName)); }
private string CleanFieldValue(ChoFixedLengthRecordFieldConfiguration config, Type fieldType, string fieldValue) { if (fieldValue.IsNull()) { return(fieldValue); } if (fieldValue != null) { ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim; if (config.FieldValueTrimOption == null) { //if (fieldType == typeof(string)) // fieldValueTrimOption = ChoFieldValueTrimOption.None; } else { fieldValueTrimOption = config.FieldValueTrimOption.Value; } switch (fieldValueTrimOption) { case ChoFieldValueTrimOption.Trim: fieldValue = fieldValue.Trim(); break; case ChoFieldValueTrimOption.TrimStart: fieldValue = fieldValue.TrimStart(); break; case ChoFieldValueTrimOption.TrimEnd: fieldValue = fieldValue.TrimEnd(); break; } } if (config.Size != null) { if (fieldValue.Length > config.Size.Value) { if (!config.Truncate) { throw new ChoParserException("Incorrect field value length found for '{0}' member [Expected: {1}, Actual: {2}].".FormatString(config.FieldName, config.Size.Value, fieldValue.Length)); } else { fieldValue = fieldValue.Substring(0, config.Size.Value); } } } if (config.QuoteField != null && config.QuoteField.Value && fieldValue.StartsWith(@"""") && fieldValue.EndsWith(@"""")) { return(fieldValue.Substring(1, fieldValue.Length - 2)); } //else if ((fieldValue.Contains(Configuration.Delimiter) // || fieldValue.Contains(Configuration.EOLDelimiter)) && fieldValue.StartsWith(@"""") && fieldValue.EndsWith(@"""")) // return fieldValue.Substring(1, fieldValue.Length - 2); else { return(fieldValue); } }
internal void WithField(string name, string yamlPath = null, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> itemConverter = null, Func <object, object> customSerializer = null, object defaultValue = null, object fallbackValue = null, string fullyQualifiedMemberName = null, string formatText = null, bool isArray = true, string nullValue = null, Type recordType = null, Type subRecordType = null, Func <IDictionary <string, object>, Type> fieldTypeSelector = null, Func <object, Type> itemRecordTypeSelector = null ) { ChoGuard.ArgumentNotNull(recordType, nameof(recordType)); if (!name.IsNullOrEmpty()) { if (subRecordType != null) { MapRecordFieldsForType(subRecordType); } string fnTrim = name.NTrim(); ChoYamlRecordFieldConfiguration fc = null; PropertyDescriptor pd = null; if (YamlRecordFieldConfigurations.Any(o => o.Name == fnTrim)) { fc = YamlRecordFieldConfigurations.Where(o => o.Name == fnTrim).First(); YamlRecordFieldConfigurations.Remove(fc); } else if (subRecordType != null) { pd = ChoTypeDescriptor.GetNestedProperty(subRecordType, fullyQualifiedMemberName.IsNullOrWhiteSpace() ? name : fullyQualifiedMemberName); } else { pd = ChoTypeDescriptor.GetNestedProperty(recordType, fullyQualifiedMemberName.IsNullOrWhiteSpace() ? name : fullyQualifiedMemberName); } var nfc = new ChoYamlRecordFieldConfiguration(fnTrim, yamlPath) { FieldType = fieldType, FieldValueTrimOption = fieldValueTrimOption, FieldName = fieldName.IsNullOrWhiteSpace() ? name : fieldName, ValueConverter = valueConverter, CustomSerializer = customSerializer, DefaultValue = defaultValue, FallbackValue = fallbackValue, FormatText = formatText, ItemConverter = itemConverter, IsArray = isArray, NullValue = nullValue, FieldTypeSelector = fieldTypeSelector, ItemRecordTypeSelector = itemRecordTypeSelector, }; if (fullyQualifiedMemberName.IsNullOrWhiteSpace()) { nfc.PropertyDescriptor = fc != null ? fc.PropertyDescriptor : pd; nfc.DeclaringMember = fc != null ? fc.DeclaringMember : fullyQualifiedMemberName; } else { if (subRecordType == null) { pd = ChoTypeDescriptor.GetNestedProperty(recordType, fullyQualifiedMemberName); } else { pd = ChoTypeDescriptor.GetNestedProperty(subRecordType, fullyQualifiedMemberName); } nfc.PropertyDescriptor = pd; nfc.DeclaringMember = fullyQualifiedMemberName; } if (pd != null) { if (nfc.FieldType == null) { nfc.FieldType = pd.PropertyType; } } if (subRecordType == null) { YamlRecordFieldConfigurations.Add(nfc); } else { AddFieldForType(subRecordType, nfc); } } }
private string CleanFieldValue(ChoCSVRecordFieldConfiguration config, Type fieldType, string fieldValue) { if (fieldValue == null) { return(fieldValue); } ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim; if (config.FieldValueTrimOption == null) { //if (fieldType == typeof(string)) // fieldValueTrimOption = ChoFieldValueTrimOption.None; } else { fieldValueTrimOption = config.FieldValueTrimOption.Value; } switch (fieldValueTrimOption) { case ChoFieldValueTrimOption.Trim: fieldValue = fieldValue.Trim(); break; case ChoFieldValueTrimOption.TrimStart: fieldValue = fieldValue.TrimStart(); break; case ChoFieldValueTrimOption.TrimEnd: fieldValue = fieldValue.TrimEnd(); break; } if (config.Size != null) { if (fieldValue.Length > config.Size.Value) { if (!config.Truncate) { throw new ChoParserException("Incorrect field value length found for '{0}' member [Expected: {1}, Actual: {2}].".FormatString(config.FieldName, config.Size.Value, fieldValue.Length)); } else { fieldValue = fieldValue.Substring(0, config.Size.Value); } } } char startChar; char endChar; //quotes are quoted and doubled (excel) i.e. 15" -> field1,"15""",field3 if (fieldValue.Contains(Configuration.DoubleQuoteChar)) { fieldValue = fieldValue.Replace(Configuration.DoubleQuoteChar, Configuration.QuoteChar.ToString()); } if (fieldValue.Contains(Configuration.BackslashQuote)) { fieldValue = fieldValue.Replace(Configuration.BackslashQuote, Configuration.QuoteChar.ToString()); } if (fieldValue.Length >= 2) { startChar = fieldValue[0]; endChar = fieldValue[fieldValue.Length - 1]; if (config.QuoteField != null && config.QuoteField.Value && startChar == Configuration.QuoteChar && endChar == Configuration.QuoteChar) { return(fieldValue.Substring(1, fieldValue.Length - 2)); } else if (startChar == Configuration.QuoteChar && endChar == Configuration.QuoteChar && (fieldValue.Contains(Configuration.Delimiter) || fieldValue.Contains(Configuration.EOLDelimiter))) { return(fieldValue.Substring(1, fieldValue.Length - 2)); } } return(fieldValue); }
public ChoJSONReader <T> WithField(string name, string jsonPath = null, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> itemConverter = null, Func <object, object> customSerializer = null, object defaultValue = null, object fallbackValue = null, string formatText = null, bool isArray = true, string nullValue = null, Func <JObject, Type> fieldTypeSelector = null) { return(WithField(name, jsonPath, fieldType, fieldValueTrimOption, fieldName, valueConverter, itemConverter, customSerializer, defaultValue, fallbackValue, null, formatText, isArray, nullValue, null, fieldTypeSelector)); }
public ChoXmlWriter <T> WithXmlAttributeField(string name, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, bool isNullable = false, object defaultValue = null, object fallbackValue = null, bool encodeValue = true, string formatText = null) { return(WithXmlAttributeField(name, fieldType, fieldValueTrimOption, fieldName, valueConverter, isNullable, defaultValue, fallbackValue, encodeValue, null, formatText)); }
public ChoXmlWriter <T> WithField(string name, string xPath = null, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, bool isXmlAttribute = false, bool isAnyXmlNode = false, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> customSerializer = null, bool isNullable = false, object defaultValue = null, object fallbackValue = null, bool encodeValue = true, string formatText = null, string nullValue = null) { return(WithField(name, xPath, fieldType, fieldValueTrimOption, isXmlAttribute, isAnyXmlNode, fieldName, valueConverter, customSerializer, isNullable, defaultValue, fallbackValue, encodeValue, null, formatText, nullValue)); }
public ChoXmlReader <T> WithXmlAttributeField(string name, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> itemConverter = null, Func <object, object> customSerializer = null, object defaultValue = null, object fallbackValue = null, bool encodeValue = false, string formatText = null, string nullValue = null) { return(WithXmlAttributeField(name, fieldType, fieldValueTrimOption, fieldName, valueConverter, itemConverter, customSerializer, defaultValue, fallbackValue, encodeValue, null, formatText, nullValue)); }
public ChoXmlWriter <T> WithXmlAttributeField <TField>(Expression <Func <T, TField> > field, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, bool isNullable = false, object defaultValue = null, object fallbackValue = null, bool encodeValue = false, string formatText = null) { if (field == null) { return(this); } return(WithXmlAttributeField(field.GetMemberName(), fieldType, fieldValueTrimOption, fieldName, valueConverter, isNullable, defaultValue, fallbackValue, encodeValue, field.GetFullyQualifiedMemberName(), formatText)); }
public ChoXmlReader <T> WithXmlElementField <TField>(Expression <Func <T, TField> > field, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> itemConverter = null, Func <object, object> customSerializer = null, object defaultValue = null, object fallbackValue = null, bool encodeValue = false, string formatText = null, string nullValue = null) { if (field == null) { return(this); } return(WithXmlElementField(field.GetMemberName(), fieldType, fieldValueTrimOption, fieldName, valueConverter, itemConverter, customSerializer, defaultValue, fallbackValue, encodeValue, field.GetFullyQualifiedMemberName(), formatText, nullValue)); }
public ChoXmlWriter <T> WithXmlAttributeField(string name, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null) { string fnTrim = name.NTrim(); string xPath = $"//@{fnTrim}"; return(WithField(fnTrim, xPath, fieldType, fieldValueTrimOption, true, fieldName)); }
public ChoJSONWriter <T> WithField <TField>(Expression <Func <T, TField> > field, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, object defaultValue = null, object fallbackValue = null, string formatText = null, string nullValue = null) { if (field == null) { return(this); } return(WithField(field.GetMemberName(), field.GetPropertyType(), fieldValueTrimOption, fieldName, valueConverter, defaultValue, fallbackValue, field.GetFullyQualifiedMemberName(), formatText, nullValue)); }
private ChoXmlWriter <T> WithXmlAttributeField(string name, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> customSerializer = null, bool isNullable = false, object defaultValue = null, object fallbackValue = null, bool encodeValue = true, string fullyQualifiedMemberName = null, string formatText = null, string nullValue = null) { string fnTrim = name.NTrim(); string xPath = $"/@{fnTrim}"; return(WithField(fnTrim, xPath, fieldType, fieldValueTrimOption, true, false, fieldName, valueConverter, customSerializer, isNullable, defaultValue, fallbackValue, encodeValue, fullyQualifiedMemberName, formatText, nullValue)); }
public ChoXmlReader <T> WithXmlElementField(string name, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null) { string fnTrim = name.NTrim(); string xPath = $"//{fnTrim}"; return(WithField(fnTrim, xPath, fieldType, fieldValueTrimOption, false, fieldName, false, valueConverter)); }
public ChoXmlWriter <T> WithField <TField>(Expression <Func <T, TField> > field, string xPath = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, bool isXmlAttribute = false, bool isAnyXmlNode = false, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> customSerializer = null, bool isNullable = false, object defaultValue = null, object fallbackValue = null, bool encodeValue = false, string formatText = null, string nullValue = null) { if (field == null) { return(this); } return(WithField(field.GetMemberName(), xPath, field.GetPropertyType(), fieldValueTrimOption, isXmlAttribute, isAnyXmlNode, fieldName, valueConverter, customSerializer, isNullable, defaultValue, fallbackValue, encodeValue, field.GetFullyQualifiedMemberName(), formatText, nullValue)); }
public ChoKVPReader <T> WithField(string name, Type fieldType, bool?quoteField = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null) { if (!name.IsNullOrEmpty()) { if (!_clearFields) { Configuration.KVPRecordFieldConfigurations.Clear(); _clearFields = true; } if (fieldName.IsNullOrWhiteSpace()) { fieldName = name; } Configuration.KVPRecordFieldConfigurations.Add(new ChoKVPRecordFieldConfiguration(name.NTrim()) { FieldType = fieldType, QuoteField = quoteField, FieldValueTrimOption = fieldValueTrimOption, FieldName = fieldName.NTrim() }); } return(this); }
private ChoXmlWriter <T> WithField(string name, string xPath = null, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, bool isXmlAttribute = false, bool isAnyXmlNode = false, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> customSerializer = null, bool isNullable = false, object defaultValue = null, object fallbackValue = null, bool encodeValue = true, string fullyQualifiedMemberName = null, string formatText = null, string nullValue = null) { if (!name.IsNullOrEmpty()) { if (!_clearFields) { ClearFields(); Configuration.MapRecordFields(Configuration.RecordType); } string fnTrim = name.NTrim(); ChoXmlRecordFieldConfiguration fc = null; PropertyDescriptor pd = null; xPath = xPath.IsNullOrWhiteSpace() ? $"/{fnTrim}" : xPath; if (Configuration.XmlRecordFieldConfigurations.Any(o => o.Name == fnTrim)) { fc = Configuration.XmlRecordFieldConfigurations.Where(o => o.Name == fnTrim).First(); Configuration.XmlRecordFieldConfigurations.Remove(fc); } else { pd = ChoTypeDescriptor.GetNestedProperty(typeof(T), fullyQualifiedMemberName.IsNullOrWhiteSpace() ? name : fullyQualifiedMemberName); } var nfc = new ChoXmlRecordFieldConfiguration(fnTrim, xPath) { FieldType = fieldType, FieldValueTrimOption = fieldValueTrimOption, IsXmlAttribute = isXmlAttribute, FieldName = fieldName, ValueConverter = valueConverter, CustomSerializer = customSerializer, IsNullable = isNullable, DefaultValue = defaultValue, FallbackValue = fallbackValue, EncodeValue = encodeValue, FormatText = formatText, IsAnyXmlNode = isAnyXmlNode, 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; } Configuration.XmlRecordFieldConfigurations.Add(nfc); } return(this); }
public ChoKVPReader <T> WithField(string name, bool?quoteField = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null) { return(WithField(name, null, quoteField, fieldValueTrimOption, fieldName)); }
public ChoJSONReader <T> WithField <TField>(Expression <Func <T, TField> > field, string jsonPath = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> itemConverter = null, Func <object, object> customSerializer = null, object defaultValue = null, object fallbackValue = null, string formatText = null, string nullValue = null, Func <JObject, Type> fieldTypeSelector = null) { if (field == null) { return(this); } return(WithField(field.GetMemberName(), jsonPath, field.GetPropertyType(), fieldValueTrimOption, fieldName, valueConverter, itemConverter, customSerializer, defaultValue, fallbackValue, field.GetFullyQualifiedMemberName(), formatText, true, nullValue, null, fieldTypeSelector)); }
public ChoXmlWriter <T> WithXmlAttributeField(string name, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, bool isNullable = false) { string fnTrim = name.NTrim(); string xPath = $"//@{fnTrim}"; return(WithField(fnTrim, xPath, fieldType, fieldValueTrimOption, true, fieldName, valueConverter, isNullable)); }
private ChoJSONReader <T> WithField(string name, string jsonPath = null, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> itemConverter = null, Func <object, object> customSerializer = null, object defaultValue = null, object fallbackValue = null, string fullyQualifiedMemberName = null, string formatText = null, bool isArray = true, string nullValue = null, Type subRecordType = null, Func <JObject, Type> fieldTypeSelector = null) { if (!name.IsNullOrEmpty()) { ClearFieldsIf(); Configuration.WithField(name, jsonPath, fieldType, fieldValueTrimOption, fieldName, valueConverter, itemConverter, customSerializer, defaultValue, fallbackValue, fullyQualifiedMemberName, formatText, isArray, nullValue, typeof(T), subRecordType, fieldTypeSelector); } return(this); }
public ChoXmlWriter <T> WithField(string name, string xPath = null, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, bool isXmlAttribute = false, string fieldName = null, Func <object, object> valueConverter = null, bool isNullable = false) { if (!name.IsNullOrEmpty()) { if (!_clearFields) { Configuration.XmlRecordFieldConfigurations.Clear(); _clearFields = true; } string fnTrim = name.NTrim(); xPath = xPath.IsNullOrWhiteSpace() ? $"//{fnTrim}" : xPath; Configuration.XmlRecordFieldConfigurations.Add(new ChoXmlRecordFieldConfiguration(fnTrim, xPath) { FieldType = fieldType, FieldValueTrimOption = fieldValueTrimOption, IsXmlAttribute = isXmlAttribute, FieldName = fieldName, ValueConverter = valueConverter, IsNullable = isNullable }); } return(this); }
public ChoJSONWriter <T> WithField(string name, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, object defaultValue = null, object fallbackValue = null, string formatText = null, string nullValue = null) { return(WithField(name, fieldType, fieldValueTrimOption, fieldName, valueConverter, defaultValue, fallbackValue, null, formatText, nullValue)); }
private string CleanFieldValue(ChoKVPRecordFieldConfiguration config, Type fieldType, string fieldValue) { if (fieldValue == null) { return(fieldValue); } ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim; if (config.FieldValueTrimOption == null) { //if (fieldType == typeof(string)) // fieldValueTrimOption = ChoFieldValueTrimOption.None; } else { fieldValueTrimOption = config.FieldValueTrimOption.Value; } switch (fieldValueTrimOption) { case ChoFieldValueTrimOption.Trim: fieldValue = fieldValue.Trim(); break; case ChoFieldValueTrimOption.TrimStart: fieldValue = fieldValue.TrimStart(); break; case ChoFieldValueTrimOption.TrimEnd: fieldValue = fieldValue.TrimEnd(); break; } if (config.Size != null) { if (fieldValue.Length > config.Size.Value) { if (!config.Truncate) { throw new ChoParserException("Incorrect field value length found for '{0}' member [Expected: {1}, Actual: {2}].".FormatString(config.FieldName, config.Size.Value, fieldValue.Length)); } else { fieldValue = fieldValue.Substring(0, config.Size.Value); } } } char startChar; char endChar; char quoteChar = Configuration.QuoteChar == '\0' ? '"' : Configuration.QuoteChar; if (fieldValue.Length >= 2) { startChar = fieldValue[0]; endChar = fieldValue[fieldValue.Length - 1]; if (config.QuoteField != null && config.QuoteField.Value && startChar == quoteChar && endChar == quoteChar) { return(fieldValue.Substring(1, fieldValue.Length - 2)); } else if (startChar == quoteChar && endChar == quoteChar && (fieldValue.Contains(Configuration.Separator) || fieldValue.Contains(Configuration.EOLDelimiter))) { return(fieldValue.Substring(1, fieldValue.Length - 2)); } } return(fieldValue); }
public ChoCSVReader <T> WithField <TField>(Expression <Func <T, TField> > field, Type fieldType = null, bool?quoteField = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, object defaultValue = null, object fallbackValue = null, string altFieldNames = null, string formatText = null) { if (field == null) { return(this); } return(WithField(field.GetMemberName(), null, fieldType, quoteField, fieldValueTrimOption, fieldName, valueConverter, defaultValue, fallbackValue, altFieldNames, field.GetFullyQualifiedMemberName(), formatText)); }
private ChoJSONReader <T> WithField(string name, string jsonPath = null, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, bool isJSONAttribute = false, string fieldName = null, Func <object, object> valueConverter = null, Func <object, object> itemConverter = null, Func <object, object> customSerializer = null, object defaultValue = null, object fallbackValue = null, string fullyQualifiedMemberName = null, string formatText = null, bool isArray = true, string nullValue = null) { if (!name.IsNullOrEmpty()) { if (!_clearFields) { ClearFields(); Configuration.MapRecordFields(Configuration.RecordType); } string fnTrim = name.NTrim(); ChoJSONRecordFieldConfiguration fc = null; PropertyDescriptor pd = null; if (Configuration.JSONRecordFieldConfigurations.Any(o => o.Name == fnTrim)) { fc = Configuration.JSONRecordFieldConfigurations.Where(o => o.Name == fnTrim).First(); Configuration.JSONRecordFieldConfigurations.Remove(fc); } else { pd = ChoTypeDescriptor.GetNestedProperty(typeof(T), fullyQualifiedMemberName.IsNullOrWhiteSpace() ? name : fullyQualifiedMemberName); } var nfc = new ChoJSONRecordFieldConfiguration(fnTrim, jsonPath) { FieldType = fieldType, FieldValueTrimOption = fieldValueTrimOption, FieldName = fieldName, ValueConverter = valueConverter, CustomSerializer = customSerializer, DefaultValue = defaultValue, FallbackValue = fallbackValue, FormatText = formatText, ItemConverter = itemConverter, IsArray = isArray, 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.JSONRecordFieldConfigurations.Add(nfc); } return(this); }
private ChoCSVReader <T> WithField(string name, int?position, Type fieldType = null, bool?quoteField = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, object defaultValue = null, object fallbackValue = null, string altFieldNames = null, string fullyQualifiedMemberName = null, string formatText = null) { 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)) { fc = Configuration.CSVRecordFieldConfigurations.Where(o => o.Name == fnTrim).First(); if (position == null) { position = fc.FieldPosition; } Configuration.CSVRecordFieldConfigurations.Remove(fc); } else { pd = ChoTypeDescriptor.GetNestedProperty(typeof(T), fullyQualifiedMemberName.IsNullOrWhiteSpace() ? name : fullyQualifiedMemberName); position = Configuration.CSVRecordFieldConfigurations.Count > 0 ? Configuration.CSVRecordFieldConfigurations.Max(f => f.FieldPosition) : 0; position++; } var nfc = new ChoCSVRecordFieldConfiguration(fnTrim, position.Value) { FieldType = fieldType, QuoteField = quoteField, FieldValueTrimOption = fieldValueTrimOption, FieldName = fieldName, ValueConverter = valueConverter, DefaultValue = defaultValue, FallbackValue = fallbackValue, AltFieldNames = altFieldNames, FormatText = formatText }; 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); }
public ChoXmlWriter <T> WithXmlElementField(string name, Type fieldType = null, ChoFieldValueTrimOption fieldValueTrimOption = ChoFieldValueTrimOption.Trim, string fieldName = null, Func <object, object> valueConverter = null, bool isNullable = false, object defaultValue = null, object fallbackValue = null) { string fnTrim = name.NTrim(); string xPath = $"//{fnTrim}"; return(WithField(fnTrim, xPath, fieldType, fieldValueTrimOption, false, fieldName, valueConverter, isNullable, defaultValue, fallbackValue)); }