Esempio n. 1
0
 public SMD()
 {
     transport           = "POST";
     envelope            = "URL";
     target              = "/json.rpc";
     additonalParameters = false;
     parameters          = new SMDAdditionalParameters[0];
     Services            = new Dictionary <string, SMDService>();
     Types      = new Dictionary <int, JObject>();
     TypeHashes = new List <string>();
 }
Esempio n. 2
0
        /// <summary>
        /// 转换参数
        /// </summary>
        /// <param name="param"></param>
        /// <param name="metaData"></param>
        /// <remarks>避免在JValue在具有显式转换器调用DeserializeObject,故尝试对常见类型进行优化</remarks>
        /// <returns></returns>
        private object ConvetParameter(object param, SMDAdditionalParameters metaData)
        {
            var jsonVal = param as JValue;

            if (jsonVal != null && (jsonVal.Value == null))
            {
                return(jsonVal.Value);
            }

            if (jsonVal != null)
            {
                if (metaData.ObjectType == typeof(string))
                {
                    return((string)jsonVal);
                }
                if (metaData.ObjectType == typeof(int))
                {
                    return((int)jsonVal);
                }
                if (metaData.ObjectType == typeof(double))
                {
                    return((double)jsonVal);
                }
                if (metaData.ObjectType == typeof(float))
                {
                    return((float)jsonVal);
                }
                if (metaData.ObjectType == typeof(decimal))
                {
                    return((decimal)jsonVal);
                }

                if (metaData.ObjectType.IsAssignableFrom(typeof(JValue)))
                {
                    return(jsonVal);
                }
            }
            else
            {
                try
                {
                    if (param is string)
                    {
                        return(JsonConvert.DeserializeObject((string)param, metaData.ObjectType));
                    }
                    return(JsonConvert.DeserializeObject(param.ToString(), metaData.ObjectType));
                }
                catch { }
            }
            return(param);
        }
Esempio n. 3
0
 public SMDResult(System.Type type)
 {
     Type       = SMDAdditionalParameters.GetTypeRecursive(type);
     ObjectType = type;
 }