Parameter Coercion (Best Practice?)

2 posts, 0 answers
  1. Xorcist
    Xorcist avatar
    98 posts
    Member since:
    Apr 2009

    Posted 20 Mar 2015 Link to this post

    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]);
              case ReportParameterType.DateTime:
                parameter.Value = Convert.ToDateTime(Parameters[parameter.Name]);
              case ReportParameterType.Float:
                parameter.Value = Convert.ToDouble(Parameters[parameter.Name]);
              case ReportParameterType.Integer:
                parameter.Value = Convert.ToInt64(Parameters[parameter.Name]);
                parameter.Value = Parameters[parameter.Name];

    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? 

  2. Hinata
    Hinata avatar
    146 posts
    Member since:
    Dec 2013

    Posted 25 Mar 2015 in reply to Xorcist Link to this post

    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.
Back to Top