Esempio n. 1
0
        /// <summary>
        /// Return multiple lists of X9Fields comprising this X9Record, where fixed-length fields are grouped together into single segments, while dynamic-length fields
        /// are placed in their own segments. Currently, this only supports one dynamic length field per record, which must come after all fixed-length fields in said record.
        ///
        /// For a record with the following fields: Fixed1, Fixed2, Fixed3, Dynamic1, the resulting segments would look like [Fixed1, Fixed2, Fixed3], [Dynamic1]
        /// </summary>
        internal List <RecordByteSegment> GetSegments()
        {
            IEnumerable <X9Field> fields = this.GetFields();

            IEnumerable <X9Field> fixedLengthFields = fields.Where(f => f.FieldType.IsFixedLength);
            X9Field dynamicLengthField = fields.FirstOrDefault(f => !f.FieldType.IsFixedLength);

            var fixedSegment = new RecordByteSegment
            {
                Offset = 0,
                Length = fixedLengthFields.Sum(f => f.FieldType.Length),
                Fields = fixedLengthFields.ToList()
            };
            List <RecordByteSegment> segs = new List <RecordByteSegment>
            {
                fixedSegment
            };

            if (dynamicLengthField != null)
            {
                segs.Add(new RecordByteSegment
                {
                    Offset = fixedSegment.Offset + fixedSegment.Length.Value,
                    Fields = new List <X9Field> {
                        dynamicLengthField
                    }
                });
            }

            return(segs);
        }
Esempio n. 2
0
 /// <summary>
 /// Compare this record to another (usually of the same type) and return whether or not they are identical.
 /// </summary>
 public bool Equals(X9Record that)
 {
     if (this.GetType() != that.GetType())
     {
         return(false);
     }
     else
     {
         List <X9Field> thisFields = this.GetFields().ToList();
         List <X9Field> thatFields = that.GetFields().ToList();
         if (thisFields.Count() != thatFields.Count())
         {
             return(false);
         }
         else
         {
             for (int i = 0; i < thisFields.Count(); i++)
             {
                 X9Field thisField = thisFields[i];
                 X9Field thatField = thatFields[i];
                 if (thisField.GetType() != thatField.GetType())
                 {
                     return(false);
                 }
                 else
                 {
                     if (thisField.GetType() == typeof(X9TextField))
                     {
                         if (!((X9TextField)thisField).Equals((X9TextField)thatField))
                         {
                             return(false);
                         }
                     }
                     else if (thisField.GetType() == typeof(X9ImageField))
                     {
                         if (!((X9ImageField)thisField).Equals((X9ImageField)thatField))
                         {
                             return(false);
                         }
                     }
                 }
             }
         }
     }
     return(true);
 }