Example #1
0
 /// <summary>
 /// Gets report parameter definitions for a target type
 /// </summary>
 /// <param name="targetType">The target types</param>
 /// <returns>A collection of parameter definitions</returns>
 public IEnumerable <ReportParameterDefinition> GetDefinitions
 (
     ReportParameterTargetType targetType
 )
 {
     return(_parameterDefinitions.Where
            (
                p => p.TargetType == targetType
            ));
 }
Example #2
0
        /// <summary>
        /// Constructs the report parameter definition with the details
        /// </summary>
        /// <param name="parameter">The parameter information</param>
        /// <param name="targetType">The target type</param>
        /// <param name="targetName">The target name</param>
        /// <param name="targetValue">The target value (optional)</param>
        internal ReportParameterDefinition
        (
            ParameterInfo parameter,
            ReportParameterTargetType targetType,
            string targetName,
            object targetValue = null
        )
        {
            Validate.IsNotNull(parameter);
            Validate.IsNotEmpty(targetName);

            this.Parameter   = parameter;
            this.TargetType  = targetType;
            this.TargetName  = targetName;
            this.TargetValue = targetValue;
        }
Example #3
0
        /// <summary>
        /// Gets parameter values for the a specific target type
        /// </summary>
        /// <param name="targetType">The target type</param>
        /// <param name="defaultValues">The default values</param>
        /// <returns>A collection of parameter values</returns>
        protected IEnumerable <ParameterValue> GetParameterValues
        (
            ReportParameterTargetType targetType,
            params ParameterValue[] defaultValues
        )
        {
            var targetValues = new List <ParameterValue>();

            var fieldDefinitions = GetDefinitions
                                   (
                targetType
                                   );

            var matchingValues = _parameterValues.Where
                                 (
                p => p.Definition.TargetType == targetType
                                 );

            if (matchingValues.Any())
            {
                targetValues.AddRange(matchingValues);
            }

            if (defaultValues != null)
            {
                foreach (var value in defaultValues)
                {
                    var valueFound = targetValues.Any
                                     (
                        v => v.Name.Equals(value.Name, StringComparison.OrdinalIgnoreCase)
                                     );

                    if (false == valueFound)
                    {
                        targetValues.Add(value);
                    }
                }
            }

            return(targetValues);
        }
Example #4
0
        /// <summary>
        /// Adds a parameter to the report definition
        /// </summary>
        /// <param name="parameter">The parameter information</param>
        /// <param name="targetType">The target type</param>
        /// <param name="targetName">The target name</param>
        /// <param name="targetValue">The target value (optional)</param>
        public void AddParameter
        (
            ParameterInfo parameter,
            ReportParameterTargetType targetType,
            string targetName,
            object targetValue = null
        )
        {
            Validate.IsNotNull(parameter);
            Validate.IsNotEmpty(targetName);

            var parameterName = parameter.Name;

            var nameUsed = this.Parameters.Any
                           (
                p => p.Parameter.Name.Equals(parameterName, StringComparison.OrdinalIgnoreCase)
                           );

            if (nameUsed)
            {
                throw new InvalidOperationException
                      (
                          $"The parameter name '{parameterName}' has already been used."
                      );
            }

            var reportParameter = new ReportParameterDefinition
                                  (
                parameter,
                targetType,
                targetName,
                targetValue
                                  );

            this.Parameters.Add(reportParameter);
        }