Esempio n. 1
0
 public static object Clone(object obj)
 {
     if (obj == null)
     {
         return(null);
     }
     if (AnonymouseHelper.IsAnonyousType(obj.GetType()))
     {
         return(AnonymouseHelper.CloneAnonyousObject(obj));
     }
     return(AnonymouseHelper.CloneAnonyousObject(obj));
 }
Esempio n. 2
0
        public static object CloneAnonyousObject(object obj)
        {
            Type type = obj.GetType();

            ParameterInfo[] parameters = type.GetConstructors()[0].GetParameters();
            object[]        array      = new object[parameters.Length];
            for (int i = 0; i < parameters.Length; i++)
            {
                PropertyInfo property = type.GetProperty(parameters[i].Name);
                object       value    = property.GetValue(obj, null);
                array[i] = AnonymouseHelper.Clone(value);
            }
            return(Activator.CreateInstance(type, array));
        }
Esempio n. 3
0
        private object ProviderCallBack(Expression expression, Type returnType)
        {
            MethodCallExpression methodCallExpression = (MethodCallExpression)expression;
            ConditionBuilder     conditionBuilder     = new ConditionBuilder();

            conditionBuilder.Build(expression, this.type, true);
            object obj = null;
            string name;

            if ((name = methodCallExpression.Method.Name) != null)
            {
                if (_sqlKeywords == null)
                {
                    _sqlKeywords = new Dictionary <string, int>(8)
                    {
                        {
                            "FirstOrDefault",
                            0
                        },

                        {
                            "First",
                            1
                        },

                        {
                            "Select",
                            2
                        },

                        {
                            "Skip",
                            3
                        },

                        {
                            "Take",
                            4
                        },

                        {
                            "OrderByDescending",
                            5
                        },

                        {
                            "OrderBy",
                            6
                        },

                        {
                            "Count",
                            7
                        }
                    };
                }
                int num;
                if (_sqlKeywords.TryGetValue(name, out num))
                {
                    DataTable dataTable;
                    switch (num)
                    {
                    case 0:
                    case 1:
                    {
                        dataTable = this.DBbase.GetDataTable(conditionBuilder.Condition, conditionBuilder.Arguments.ToArray());
                        object obj2;
                        if (AnonymouseHelper.IsAnonyousType(returnType))
                        {
                            obj2 = ConvertHelper.GetAnonymous(dataTable, returnType);
                        }
                        else
                        {
                            obj2 = ConvertHelper.GetList(dataTable, returnType);
                        }
                        IEnumerable enumerable = (IEnumerable)obj2;
                        IEnumerator enumerator = enumerable.GetEnumerator();
                        try
                        {
                            if (enumerator.MoveNext())
                            {
                                object current = enumerator.Current;
                                obj = current;
                            }
                            return(obj);
                        }
                        finally
                        {
                            IDisposable disposable = enumerator as IDisposable;
                            if (disposable != null)
                            {
                                disposable.Dispose();
                            }
                        }
                        break;
                    }

                    case 2:
                    case 3:
                    case 4:
                    case 5:
                    case 6:
                        break;

                    case 7:
                        obj = this.DBbase.GetSingle(conditionBuilder.Condition, conditionBuilder.Arguments.ToArray());
                        obj = Convert.ToInt32(obj);
                        return(obj);

                    default:
                        return(obj);
                    }
                    Type[] genericArguments = returnType.GetGenericArguments();
                    returnType = ((genericArguments.Length == 0) ? this.type : genericArguments[0]);
                    dataTable  = this.DBbase.GetDataTable(conditionBuilder.Condition, conditionBuilder.Arguments.ToArray());
                    if (AnonymouseHelper.IsAnonyousType(returnType))
                    {
                        obj = ConvertHelper.GetAnonymous(dataTable, returnType);
                    }
                    else
                    {
                        obj = ConvertHelper.GetList(dataTable, returnType);
                    }
                    obj = (IEnumerable)obj;
                }
            }
            return(obj);
        }