/// <summary>
        /// Confirm all fields are either ordered or unordered
        /// </summary>
        /// <param name="currentField">Newest field</param>
        /// <param name="resFields">Other fields we have found</param>
        private static void CheckForOrderProblems(FieldBase currentField, List <FieldBase> resFields)
        {
            if (currentField.FieldOrder.HasValue)
            {
                // If one field has order number set, all others must also have an order number
                var fieldWithoutOrder = resFields.Find(x => x.FieldOrder.HasValue == false);
                if (fieldWithoutOrder != null)
                {
                    throw new BadUsageException(Messages.Errors.PartialFieldOrder
                                                .FieldName(fieldWithoutOrder.FieldInfo.Name)
                                                .Text);
                }

                // No other field should have the same order number
                var fieldWithSameOrder =
                    resFields.Find(x => x != currentField && x.FieldOrder == currentField.FieldOrder);

                if (fieldWithSameOrder != null)
                {
                    throw new BadUsageException(Messages.Errors.SameFieldOrder
                                                .FieldName1(currentField.FieldInfo.Name)
                                                .FieldName2(fieldWithSameOrder.FieldInfo.Name)
                                                .Text);
                }
            }
            else
            {
                // No other field should have order number set
                var fieldWithOrder = resFields.Find(x => x.FieldOrder.HasValue);
                if (fieldWithOrder != null)
                {
                    var autoPropertyName = FieldBase.AutoPropertyName(currentField.FieldInfo);

                    if (string.IsNullOrEmpty(autoPropertyName))
                    {
                        throw new BadUsageException(Messages.Errors.PartialFieldOrder
                                                    .FieldName(currentField.FieldInfo.Name)
                                                    .Text);
                    }
                    else
                    {
                        throw new BadUsageException(Messages.Errors.PartialFieldOrderInAutoProperty
                                                    .PropertyName(autoPropertyName)
                                                    .Text);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Confirm all fields are either ordered or unordered
        /// </summary>
        /// <param name="currentField">Newest field</param>
        /// <param name="resFields">Other fields we have found</param>
        private static void CheckForOrderProblems(FieldBase currentField, List <FieldBase> resFields)
        {
            if (currentField.FieldOrder.HasValue)
            {
                // If one field has order number set, all others must also have an order number
                var fieldWithoutOrder = resFields.Find(x => x.FieldOrder.HasValue == false);
                if (fieldWithoutOrder != null)
                {
                    throw new BadUsageException($"The field: {fieldWithoutOrder.FieldInfo.Name} must be marked with FieldOrder because if you use this attribute in one field you must also use it on all of them.");
                }

                // No other field should have the same order number
                var fieldWithSameOrder =
                    resFields.Find(x => x != currentField && x.FieldOrder == currentField.FieldOrder);

                if (fieldWithSameOrder != null)
                {
                    throw new BadUsageException($"The field: {currentField.FieldInfo.Name} has the same FieldOrder as: {fieldWithSameOrder.FieldInfo.Name}. You must use different values");
                }
            }
            else
            {
                // No other field should have order number set
                var fieldWithOrder = resFields.Find(x => x.FieldOrder.HasValue);
                if (fieldWithOrder != null)
                {
                    var autoPropertyName = FieldBase.AutoPropertyName(currentField.FieldInfo);

                    if (string.IsNullOrEmpty(autoPropertyName))
                    {
                        throw new BadUsageException($"The field: {currentField.FieldInfo.Name} must be marked with FieldOrder because if you use this attribute in one field you must also use it on all of them.");
                    }
                    else
                    {
                        throw new BadUsageException(
                                  $"The auto property: {autoPropertyName} must be marked with FieldOrder because if you use this attribute in one field you must also use it on all of them.");
                    }
                }
            }
        }