示例#1
0
 public void Clear()
 {
     parameters = new SMDAdditionalParameters[0];
     Services   = new Dictionary <string, SMDService>();
     Types      = new Dictionary <int, JObject>();
     TypeHashes = new List <string>();
 }
示例#2
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>();
 }
示例#3
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>();
	    }
示例#4
0
        private object CleanUpParameter(object p, SMDAdditionalParameters metaData)
        {
            var bob = p as JValue;

            if (bob != null && (bob.Value == null || bob.Value.GetType() == metaData.ObjectType))
            {
                return(bob.Value);
            }

            var paramI = p;

            try
            {
                return(Newtonsoft.Json.JsonConvert.DeserializeObject(paramI.ToString(), metaData.ObjectType));
            }
            catch (Exception ex)
            {
                // no need to throw here, they will
                // get an invalid cast exception right after this.
            }

            return(paramI);
        }
示例#5
0
        private object CleanUpParameter(object p, SMDAdditionalParameters metaData)
        {
            var bob = p as JValue;
            //if (bob != null && (bob.Value == null || bob.Value.GetType() == metaData.ObjectType))
            if (bob != null && (bob.Value == null || metaData.ObjectType.IsAssignableFrom(bob.Value.GetType())))
            {
                return bob.Value;
            }

            var paramI = p;
            try
            {
                return Newtonsoft.Json.JsonConvert.DeserializeObject(paramI.ToString(), metaData.ObjectType);
            }
            catch (Exception ex)
            {
                // no need to throw here, they will
                // get an invalid cast exception right after this.
            }

            return paramI;
        }
示例#6
0
        private object CleanUpParameter(object p, SMDAdditionalParameters metaData)
        {
            var bob = p as JValue;

            if (bob != null)
            {
                if (bob.Value == null || metaData.ObjectType == bob.Value.GetType())
                {
                    return(bob.Value);
                }

                // Avoid calling DeserializeObject on types that JValue has an explicit converter for
                // try to optimize for the most common types
                if (metaData.ObjectType == typeof(string))
                {
                    return((string)bob);
                }
                if (metaData.ObjectType == typeof(int))
                {
                    return((int)bob);
                }
                if (metaData.ObjectType == typeof(double))
                {
                    return((double)bob);
                }
                if (metaData.ObjectType == typeof(float))
                {
                    return((float)bob);
                }
                //if (metaData.ObjectType == typeof(long)) return (long)bob;
                //if (metaData.ObjectType == typeof(uint)) return (uint)bob;
                //if (metaData.ObjectType == typeof(ulong)) return (ulong)bob;
                //if (metaData.ObjectType == typeof(byte[])) return (byte[])bob;
                //if (metaData.ObjectType == typeof(Guid)) return (Guid)bob;
                if (metaData.ObjectType == typeof(decimal))
                {
                    return((decimal)bob);
                }
                //if (metaData.ObjectType == typeof(TimeSpan)) return (TimeSpan)bob;
                //if (metaData.ObjectType == typeof(short)) return (short)bob;
                //if (metaData.ObjectType == typeof(ushort)) return (ushort)bob;
                //if (metaData.ObjectType == typeof(char)) return (char)bob;
                //if (metaData.ObjectType == typeof(DateTime)) return (DateTime)bob;
                //if (metaData.ObjectType == typeof(bool)) return (bool)bob;
                //if (metaData.ObjectType == typeof(DateTimeOffset)) return (DateTimeOffset)bob;

                if (metaData.ObjectType.IsAssignableFrom(typeof(JValue)))
                {
                    return(bob);
                }

                try
                {
                    return(bob.ToObject(metaData.ObjectType));
                }
                catch (Exception ex)
                {
                    // no need to throw here, they will
                    // get an invalid cast exception right after this.
                }
            }
            else
            {
                try
                {
                    if (p is string)
                    {
                        return(JsonConvert.DeserializeObject((string)p, metaData.ObjectType));
                    }
                    return(JsonConvert.DeserializeObject(p.ToString(), metaData.ObjectType));
                }
                catch (Exception ex)
                {
                    // no need to throw here, they will
                    // get an invalid cast exception right after this.
                }
            }

            return(p);
        }
示例#7
0
 public SMDResult(System.Type type)
 {
     Type = SMDAdditionalParameters.GetTypeRecursive(type);
 }
示例#8
0
        private object CleanUpParameter(object p, SMDAdditionalParameters metaData)
        {
            var bob = p as JValue;
            //if (bob != null && (bob.Value == null || bob.Value.GetType() == metaData.ObjectType))
            if (bob != null && (bob.Value == null))
            {
                return bob.Value;
            }
            if (bob != null)
            {

                // Avoid calling DeserializeObject on types that JValue has an explicit converter for
                // try to optimize for the most common types
                if (metaData.ObjectType == typeof(string)) return (string)bob;
                if (metaData.ObjectType == typeof(int)) return (int)bob;
                if (metaData.ObjectType == typeof(double)) return (double)bob;
                if (metaData.ObjectType == typeof(float)) return (float)bob;
                //if (metaData.ObjectType == typeof(long)) return (long)bob;
                //if (metaData.ObjectType == typeof(uint)) return (uint)bob;
                //if (metaData.ObjectType == typeof(ulong)) return (ulong)bob;
                //if (metaData.ObjectType == typeof(byte[])) return (byte[])bob;
                //if (metaData.ObjectType == typeof(Guid)) return (Guid)bob;
                if (metaData.ObjectType == typeof(decimal)) return (decimal)bob;
                //if (metaData.ObjectType == typeof(TimeSpan)) return (TimeSpan)bob;
                //if (metaData.ObjectType == typeof(short)) return (short)bob;
                //if (metaData.ObjectType == typeof(ushort)) return (ushort)bob;
                //if (metaData.ObjectType == typeof(char)) return (char)bob;
                //if (metaData.ObjectType == typeof(DateTime)) return (DateTime)bob;
                //if (metaData.ObjectType == typeof(bool)) return (bool)bob;
                //if (metaData.ObjectType == typeof(DateTimeOffset)) return (DateTimeOffset)bob;

                if (metaData.ObjectType.IsAssignableFrom(typeof(JValue)))
                    return bob;

                try
                {
                    return bob.ToObject(metaData.ObjectType);
                }
                catch (Exception ex)
                {
                    // no need to throw here, they will
                    // get an invalid cast exception right after this.
                }
            }
            else
            {
                try
                {
                    if (p is string)
                        return JsonConvert.DeserializeObject((string)p, metaData.ObjectType);
                    return JsonConvert.DeserializeObject(p.ToString(), metaData.ObjectType);
                }
                catch (Exception ex)
                {
                    // no need to throw here, they will
                    // get an invalid cast exception right after this.
                }
            }

            return p;
        }