This is a migrated thread and some comments may be shown as answers.

Parameter Coercion (Best Practice?)

1 Answer 59 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Xorcist
Top achievements
Rank 1
Xorcist asked on 20 Mar 2015, 06:01 PM
I am dynamically reading parameters for my reports from either a posted web form or a querystring, and as such they're all strings. Currently I loop through the parameters in my report, and match up the supplied parameter names to do an assignment like this:

      foreach (ReportParameter parameter in MyReportSource.ReportDocument.ReportParameters) {
        switch (parameter.Type) {
          case ReportParameterType.Boolean:
            parameter.Value = Convert.ToBoolean(Parameters[parameter.Name]);
          break;
          case ReportParameterType.DateTime:
            parameter.Value = Convert.ToDateTime(Parameters[parameter.Name]);
          break;
          case ReportParameterType.Float:
            parameter.Value = Convert.ToDouble(Parameters[parameter.Name]);
          break;
          case ReportParameterType.Integer:
            parameter.Value = Convert.ToInt64(Parameters[parameter.Name]);
          break;
          default:
            parameter.Value = Parameters[parameter.Name];
          break;
        }
      }

is there a better way to do this? If at some point Telerik adds a new parameter type, I have to go in and change this code (which I'd like to prevent). Can I just use:

      parameter.Value = Parameters[parameter.Name];

does Telerik take the Value and internally covert it? or would just passing along all the Strings potential cause me issues later with things like validation and default values? 





1 Answer, 1 is accepted

Sort by
0
Hinata
Top achievements
Rank 1
answered on 25 Mar 2015, 02:03 PM
Hi Xorcist,

You can set the parameter value as an expression, which will be processed by the engine:

parameter.Value = "= \"" + Parameters[parameter.Name] + "\"";

This will be the same as setting the parameter's default value at design-time to = "true" or = "12/12/2015"
which will be parsed automatically by the engine.
Tags
General Discussions
Asked by
Xorcist
Top achievements
Rank 1
Answers by
Hinata
Top achievements
Rank 1
Share this question
or