Example #1
0
        private string[] fCreateRemainingFieldsArray(RecordFields aRecordFields, int aStartIndex)
        {
            List <string> temp  = new List <string>();
            int           count = aRecordFields.Count;
            int           i     = aStartIndex;

            if (i <= count)
            {
                count++;
                do
                {
                    temp.Add(aRecordFields.GetField(i));
                    i++;
                }while (i != count);
            }
            return(temp.ToArray());
        }
Example #2
0
        public AbstractLisRecord(string aLisString)
        {
            bool isSubRecord = this is AbstractLisSubRecord;
            char sepChar     = ((!isSubRecord) ? LISDelimiters.FieldDelimiter : LISDelimiters.ComponentDelimiter);
            Type selfType    = this?.GetType();

            PropertyInfo[] props = selfType.GetProperties();
            int            limit = int.MaxValue;

            if (isSubRecord && (int)props.LongLength > 0 && !props[(int)props.LongLength - 1].PropertyType.IsArray)
            {
                limit = props.Length;
            }
            RecordFields rf = new RecordFields(aLisString, sepChar, limit);
            int          i  = 0;

            PropertyInfo[] array = props;
            if (array == null)
            {
                return;
            }
            for (; i < (int)array.LongLength; i++)
            {
                PropertyInfo prop    = array[i];
                object[]     attribs = prop.GetCustomAttributes(typeof(LisRecordFieldAttribute), inherit: false);
                if ((int)attribs.LongLength <= 0)
                {
                    continue;
                }
                LisRecordFieldAttribute attrib = (LisRecordFieldAttribute)attribs[0];
                string field = rf.GetField(attrib.FieldIndex);
                if (string.IsNullOrEmpty(field))
                {
                    continue;
                }
                Type propType         = prop.PropertyType;
                Type nullablePropType = Nullable.GetUnderlyingType(propType);
                if ((object)nullablePropType != null)
                {
                    propType = nullablePropType;
                }
                if (!(propType == typeof(int)))
                {
                    if (!(propType == typeof(string)))
                    {
                        if (propType == typeof(DateTime))
                        {
                            LisDateTimeUsage dateTimeUsage = LisDateTimeUsage.DateTime;
                            attribs = prop.GetCustomAttributes(typeof(LisDateTimeUsageAttribute), inherit: false);
                            if ((int)attribs.LongLength == 1)
                            {
                                LisDateTimeUsageAttribute dtAttrib = (LisDateTimeUsageAttribute)attribs[0];
                                dateTimeUsage = dtAttrib.DateTimeUsage;
                            }
                            prop.SetValue(this, fRemoveOptionalSubFields(field).LisStringToDateTime(dateTimeUsage), null);
                        }
                        else if (propType.IsEnum)
                        {
                            prop.SetValue(this, fCreateLisEnum(fRemoveOptionalSubFields(field), propType), null);
                        }
                        else if (propType.BaseType == typeof(AbstractLisSubRecord))
                        {
                            prop.SetValue(this, fCreateSubrecord(field, propType), null);
                        }
                        else if (propType.IsArray)
                        {
                            if (!(attrib is LisRecordRemainingFieldsAttribute))
                            {
                                throw new FormatException("The LIS String was not of the correct format.");
                            }
                            prop.SetValue(this, fCreateRemainingFieldsArray(rf, attrib.FieldIndex), null);
                        }
                    }
                    else
                    {
                        prop.SetValue(this, field, null);
                    }
                }
                else
                {
                    prop.SetValue(this, int.Parse(fRemoveOptionalSubFields(field)), null);
                }
            }
        }