Ejemplo n.º 1
0
 protected FieldSettingsBase(MemberInfo member)
 {
     Type             = member.MemberType();
     Member           = member;
     DefaultConverter = Type.GetConverter();
     UniqueKey        = $"[{member.DeclaringType.AssemblyQualifiedName}]:{member.Name}";
     _getValue        = ReflectionHelper.CreateMemberGetter(member);
     _setValue        = ReflectionHelper.CreateMemberSetter(member);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Specifies that a field's value should be converted to a string from its source type using the provided conversion function.
        /// </summary>
        /// <typeparam name="TProperty">The type of the source property.</typeparam>
        /// <param name="formatter">A lambda function converting to a string.</param>
        public IDelimitedFieldSettingsBuilder WithConversionToString <TProperty>(FieldFormatter <TProperty> formatter)
        {
            if (_converter == null)
            {
                _converter = new DelegatingConverter <TProperty>();
            }

            if (_converter is DelegatingConverter <TProperty> delegatingConverter)
            {
                delegatingConverter.FormatValue = formatter;
            }
            else
            {
                throw new InvalidOperationException("A converter has already been explicitly set.");
            }

            return(this);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Specifies that a field's value should be converted from a string to its destination type using the provided conversion function.
        /// </summary>
        /// <typeparam name="TProperty">The type of the destination property.</typeparam>
        /// <param name="parser">A lambda function converting from a string.</param>
        public IFixedFieldSettingsBuilder WithConversionFromString <TProperty>(FieldParser <TProperty> parser)
        {
            if (parser == null)
            {
                throw new ArgumentNullException(nameof(parser));
            }

            if (_converter == null)
            {
                _converter = new DelegatingConverter <TProperty>();
            }

            if (_converter is DelegatingConverter <TProperty> delegatingConverter)
            {
                delegatingConverter.ParseValue = parser;
            }
            else
            {
                throw new InvalidOperationException("A converter has already been explicitly set.");
            }

            return(this);
        }
Ejemplo n.º 4
0
 /// <summary>
 ///  Specifies that a field's value should be converted using the provided <see cref="IFieldValueConverter"/> implementation.
 /// </summary>
 /// <param name="converter">The converter to use.</param>
 public IFixedFieldSettingsBuilder WithConverter(IFieldValueConverter converter)
 {
     _converter = converter ?? throw new ArgumentNullException(nameof(converter));
     return(this);
 }
 public FieldDefinition Converter <T>() where T : IFieldValueConverter, new()
 {
     this.FieldConverter = new T();
     return(this);
 }