Esempio n. 1
0
 protected object Cast(List <string> objList, StatementParameter param)
 {
     try
     {
         if (objList.Count == 1)
         {
             if (param.Type == typeof(List <string>))
             {
                 return(objList);
             }
             else
             {
                 // Convert a simple string
                 return(Convert.ChangeType(objList[0], param.Type));
             }
         }
         else
         {
             // Or convert a more complex array
             return(Convert.ChangeType(objList, param.Type));
         }
     }
     catch
     {
         throw new CannotLinkStatementException(definition.MethodInfo,
                                                string.Format("Cannot convert '{0}' into {1}, to match parameter '{2}'",
                                                              objList, param.Type, param.Name))
               {
                   Statement = Statement
               };
     }
 }
 protected object Cast(string obj, StatementParameter param)
 {
     try { return Convert.ChangeType(obj, param.Type); }
     catch(FormatException e)
     {
         throw new CannotLinkStatementException(definition.MethodInfo,
             string.Format("Cannot convert '{0}' into {1}, to match parameter '{2}'",
             obj, param.Type, param.Name))
             {
                 Statement = Statement
             };
     }
 }