Пример #1
0
        public WMap(object source)
        {
            map = WUtil.ToDictionary(source);

            if (map == null)
            {
                map = new Dictionary <string, object>();
            }
        }
Пример #2
0
        public IDictionary <string, object> GetDictionary(string key, bool notNull = false)
        {
            if (map.ContainsKey(key))
            {
                return(WUtil.ToDictionary(map[key]));
            }

            if (notNull)
            {
                return(new Dictionary <string, object>());
            }

            return(null);
        }
Пример #3
0
        public IDictionary<string, object> GetDictionary(int index, bool notNull = false)
        {
            object value = list[index];

            if (value != null)
            {
                return WUtil.ToDictionary(value);
            }

            if (notNull)
            {
                return new Dictionary<string, object>();
            }

            return null;
        }
Пример #4
0
        public static object[] GetParameters(ParameterInfo[] arrayOfParameterInfo, object[] parameters)
        {
            if (arrayOfParameterInfo.Length != parameters.Length)
            {
                return(null);
            }

            for (int i = 0; i < arrayOfParameterInfo.Length; i++)
            {
                object value = parameters[i];

                if (value == null)
                {
                    continue;
                }

                ParameterInfo parameterInfo = arrayOfParameterInfo[i];

                Type typePar = parameterInfo.ParameterType;

                if (value is JValue)
                {
                    value = ((JValue)value).Value;

                    parameters[i] = value;
                }

                Type typeObj = value.GetType();

                if (!typePar.IsAssignableFrom(typeObj))
                {
                    var typeParName = typePar.Namespace + "." + typePar.Name;

                    if (!typeParName.StartsWith("System."))
                    {
                        // IDictionary -> Data Class

                        if (value is IDictionary <string, object> )
                        {
                            parameters[i] = WUtil.CreateObject((IDictionary <string, object>)value, typePar);
                            continue;
                        }
                        else if (value is JObject)
                        {
                            parameters[i] = WUtil.CreateObject((JObject)value, typePar);
                            continue;
                        }
                    }
                    else if (typeof(IDictionary <string, object>).IsAssignableFrom(typePar))
                    {
                        // Data Class -> IDictionary

                        var typeObjName = typeObj.Namespace + "." + typeObj.Name;

                        if (value is IDictionary <string, object> )
                        {
                            continue;
                        }
                        else if (value is JObject)
                        {
                            parameters[i] = WUtil.ToDictionary(value);
                            continue;
                        }
                        else if (!typeObjName.StartsWith("System."))
                        {
                            parameters[i] = WUtil.ToDictionary(value);
                            continue;
                        }
                    }
                    else if (typeof(Array).IsAssignableFrom(typePar))
                    {
                        parameters[i] = WUtil.ToArrayOf(value, typePar.GetElementType());
                        continue;
                    }
                    else if (typeof(IEnumerable <object>).IsAssignableFrom(typePar))
                    {
                        Type elementType = typePar.GetElementType();
                        if (elementType == null)
                        {
                            Type[] generciArguments = typePar.GetGenericArguments();
                            elementType = generciArguments != null && generciArguments.Length > 0 ? generciArguments[0] : null;
                        }
                        parameters[i] = WUtil.ToListOf(value, elementType);
                        continue;
                    }
                    else if (value is Int64)
                    {
                        if (typePar.Equals(typeof(Int32)))
                        {
                            parameters[i] = Convert.ToInt32(value);
                            continue;
                        }
                        else if (typePar.Equals(typeof(Double)))
                        {
                            parameters[i] = Convert.ToDouble(value);
                            continue;
                        }
                    }
                    else if (value is Int32)
                    {
                        if (typePar.Equals(typeof(Int64)))
                        {
                            parameters[i] = Convert.ToInt64(value);
                            continue;
                        }
                        else if (typePar.Equals(typeof(Double)))
                        {
                            parameters[i] = Convert.ToDouble(value);
                            continue;
                        }
                    }
                    else if (value is Double)
                    {
                        if (typePar.Equals(typeof(Int32)))
                        {
                            parameters[i] = Convert.ToInt32(value);
                            continue;
                        }
                        else if (typePar.Equals(typeof(Int64)))
                        {
                            parameters[i] = Convert.ToInt64(value);
                            continue;
                        }
                    }
                    return(null);
                }
            }

            return(parameters);
        }