Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FieldDescriptor"/> class.
        /// </summary>
        /// <param name="lengthFormatter">
        /// The length formatter.
        /// </param>
        /// <param name="validator">
        /// The validator.
        /// </param>
        /// <param name="formatter">
        /// The formatter.
        /// </param>
        /// <param name="adjuster">
        /// The adjuster.
        /// </param>
        public FieldDescriptor(ILengthFormatter lengthFormatter, IFieldValidator validator, IFormatter formatter, Adjuster adjuster)
        {
            if (formatter is BinaryFormatter && !(validator is HexFieldValidator))
            {
                throw new FieldDescriptorException("A Binary field must have a hex validator");
            }

            if (formatter is BcdFormatter && !(validator is NumericFieldValidator))
            {
                throw new FieldDescriptorException("A BCD field must have a numeric validator");
            }

            this.LengthFormatter = lengthFormatter;
            this.Validator       = validator;
            this.Formatter       = formatter;
            Adjuster             = adjuster;
        }
Example #2
0
 /// <summary>
 /// Create a field descriptor
 /// </summary>
 /// <param name="lengthFormatter">
 /// The length formatter.
 /// </param>
 /// <param name="fieldValidator">
 /// The field validator.
 /// </param>
 /// <param name="formatter">
 /// The formatter.
 /// </param>
 /// <param name="adjuster">
 /// The adjuster.
 /// </param>
 /// <returns>
 /// A field descriptor
 /// </returns>
 public static IFieldDescriptor Create(ILengthFormatter lengthFormatter, IFieldValidator fieldValidator, IFormatter formatter, Adjuster adjuster)
 {
     return(new FieldDescriptor(lengthFormatter, fieldValidator, formatter, adjuster));
 }