/// <summary> /// Parses given Values from RegEx GroupCollection as typed array /// </summary> /// <param name="value">GroupCollectionValues</param> /// <param name="p">ParameterInfoAttibute of Array</param> /// <param name="idx">Index of GroupItem</param> /// <param name="groupOffset">GroupOffset dto increase</param> /// <returns>typed array boxed in an object</returns> private object ParseArray(GroupCollection value, ParameterInfo p, int idx, ref int groupOffset) { ParameterInfoAttribute parameterAttribute = p.GetCustomAttribute <ParameterInfoAttribute>(); ArrayList list = new ArrayList(); for (int i = 0; i < parameterAttribute.ArrayLength; i++) { object parsedValue = ParseValue(value[idx + i + 1].Value, p.ParameterType.GetElementType()); ValidateParameterRestrictions(parsedValue, p); list.Add(parsedValue); } groupOffset += parameterAttribute.ArrayLength - 1; return((object)list.ToArray(p.ParameterType.GetElementType())); }
/// <summary> /// Validates an input object if it fullfills the definition of a parameterInfo /// </summary> /// <param name="input">Object to validate</param> /// <param name="p">ParameterInfo definition</param> private static void ValidateParameterRestrictions(object input, ParameterInfo p) { ParameterInfoAttribute parameterAttribute = p.GetCustomAttribute <ParameterInfoAttribute>(); if (parameterAttribute != null && input.IsNumericType()) { if (Convert.ToDecimal(input) > parameterAttribute.MaxValue) { throw new ArgumentParserException(string.Format("Given parameter '{0}' is greater than defined MaxValue {1}", input, parameterAttribute.MaxValue)); } else if (Convert.ToDecimal(input) < parameterAttribute.MinValue) { throw new ArgumentParserException(string.Format("Given parameter '{0}' is smaller than defined MinValue {1}", input, parameterAttribute.MinValue)); } } }