コード例 #1
0
        /// <summary>
        /// Converts a submitted parameter value into the value type expected
        /// </summary>
        /// <param name="filter">The report filter</param>
        /// <param name="submittedValue">The submitted value</param>
        /// <returns>The converted value</returns>
        private object ConvertParameterValue
        (
            ReportFilter filter,
            SubmittedParameterValue submittedValue
        )
        {
            if (submittedValue.Value == null)
            {
                return(null);
            }

            var definition = filter.GetDefinition
                             (
                submittedValue.ParameterName
                             );

            var expectedType = definition.Parameter.ExpectedType;

            if (expectedType == typeof(string))
            {
                return(submittedValue.Value);
            }
            else
            {
                return(ObjectConverter.Convert
                       (
                           submittedValue.Value,
                           expectedType
                       ));
            }
        }
コード例 #2
0
        /// <summary>
        /// Converts a submitted parameter value into the value type expected
        /// </summary>
        /// <param name="filter">The report filter</param>
        /// <param name="submittedValue">The submitted value</param>
        /// <returns>The converted value</returns>
        private object ConvertParameterValue
        (
            ReportFilter filter,
            SubmittedParameterValue submittedValue
        )
        {
            if (submittedValue.Values == null)
            {
                return(null);
            }

            var definition = filter.GetDefinition
                             (
                submittedValue.ParameterName
                             );

            var expectedType = definition.Parameter.ExpectedType;

            if (expectedType.IsArray)
            {
                expectedType = expectedType.GetElementType();

                var convertedValues = Array.CreateInstance
                                      (
                    expectedType,
                    submittedValue.Values.Length
                                      );

                var index = 0;

                foreach (var rawValue in submittedValue.Values)
                {
                    convertedValues.SetValue
                    (
                        ConvertValue(rawValue),
                        index
                    );

                    index++;
                }

                return(convertedValues);
            }
            else if (submittedValue.Values.Length == 0)
            {
                return(null);
            }
            else
            {
                return(ConvertValue
                       (
                           submittedValue.Values[0]
                       ));
            }

            object ConvertValue(string value)
            {
                if (expectedType == typeof(string))
                {
                    return(value);
                }
                else
                {
                    return(ObjectConverter.Convert
                           (
                               value,
                               expectedType
                           ));
                }
            }
        }