/// <summary> /// Parse the attributes on the class and create an ordered list of /// fields we are extracting from the record /// </summary> /// <param name="fields">Complete list of fields in class</param> /// <param name="recordAttribute">Type of record, fixed or delimited</param> /// <returns>List of fields we are extracting</returns> private static FieldBase[] CreateCoreFields(IList <FieldInfo> fields, TypedRecordAttribute recordAttribute) { var resFields = new List <FieldBase>(); // count of Properties var automaticFields = 0; // count of normal fields var genericFields = 0; for (int i = 0; i < fields.Count; i++) { FieldBase currentField = FieldBase.CreateField(fields[i], recordAttribute); if (currentField == null) { continue; } if (currentField.FieldInfo.IsDefined(typeof(CompilerGeneratedAttribute), false)) { automaticFields++; } else { genericFields++; } // Add to the result resFields.Add(currentField); if (resFields.Count > 1) { CheckForOrderProblems(currentField, resFields); } } if (automaticFields > 0 && genericFields > 0) { throw new BadUsageException(Messages.Errors.MixOfStandardAndAutoPropertiesFields .ClassName(resFields[0].FieldInfo.DeclaringType.Name) .Text); } SortFieldsByOrder(resFields); if (resFields.Count > 0) { resFields[0].IsFirst = true; resFields[resFields.Count - 1].IsLast = true; } CheckForOptionalAndArrayProblems(resFields); return(resFields.ToArray()); }
private static FieldBase[] CreateCoreFields(List <FieldInfo> fields, TypedRecordAttribute recordAttribute) { List <FieldBase> resFields = new List <FieldBase>(); for (int i = 0; i < fields.Count; i++) { FieldBase currentField = FieldBase.CreateField((FieldInfo)fields[i], recordAttribute); if (currentField != null) { // Add to the result resFields.Add(currentField); // Check some differences with the previous field if (resFields.Count > 1) { FieldBase prevField = (FieldBase)resFields[resFields.Count - 2]; prevField.mNextIsOptional = currentField.mIsOptional; // Check for optional problems if (prevField.mIsOptional && currentField.mIsOptional == false) { throw new BadUsageException("The field: " + prevField.mFieldInfo.Name + " must be marked as optional bacause after a field with FieldOptional, the next fields must be marked with the same attribute. ( Try adding [FieldOptional] to " + currentField.mFieldInfo.Name + " )"); } // Check for array problems if (prevField.mIsArray) { if (prevField.mArrayMinLength == int.MinValue) { throw new BadUsageException("The field: " + prevField.mFieldInfo.Name + " is an array and must contain a [FieldArrayLength] attribute because not is the last field."); } if (prevField.mArrayMinLength != prevField.mArrayMaxLength) { throw new BadUsageException("The array field: " + prevField.mFieldInfo.Name + " must contain a fixed length, i.e. the min and max length of the [FieldArrayLength] attribute must be the same because not is the last field."); } } } } } if (resFields.Count > 0) { ((FieldBase)resFields[0]).mIsFirst = true; ((FieldBase)resFields[resFields.Count - 1]).mIsLast = true; } return(resFields.ToArray()); }
/// <summary> /// Parse the attributes on the class and create an ordered list of /// fields we are extracting from the record /// </summary> /// <param name="fields">Complete list of fields in class</param> /// <param name="recordAttribute">Type of record, fixed or delimited</param> /// <returns>List of fields we are extracting</returns> private static FieldBase[] CreateCoreFields(IList <FieldInfo> fields, TypedRecordAttribute recordAttribute) { var resFields = new List <FieldBase>(); // count of Properties var automaticFields = 0; // count of normal fields var genericFields = 0; for (int i = 0; i < fields.Count; i++) { FieldBase currentField = FieldBase.CreateField(fields[i], recordAttribute); if (currentField == null) { continue; } if (currentField.FieldInfo.IsDefined(typeof(CompilerGeneratedAttribute), false)) { automaticFields++; } else { genericFields++; } // Add to the result resFields.Add(currentField); if (resFields.Count > 1) { CheckForOrderProblems(currentField, resFields); } } if (automaticFields > 0 && genericFields > 0 && SumOrder(resFields) == 0) { throw new BadUsageException( $"You can mix standard fields and automatic properties only if you use [FieldOrder()] over the fields and properties in the {resFields[0].FieldInfo.DeclaringType.Name} class."); } SortFieldsByOrder(resFields); CheckForOptionalAndArrayProblems(resFields); return(resFields.ToArray()); }