Commits

George Ribeiro committed 83b2501

criada a clasula order by

Comments (0)

Files changed (25)

FluentSql.Test/Api/TestField.cs

         public void Criar_Field_Sem_Alias()
         {
             var f = new Field(new Table("users"), "nome");
-            Assert.AreEqual("users.nome", f.ToSql());
+            Assert.AreEqual("users.nome", f.AsProject());
             Assert.AreEqual("users.nome", f.Project);
             Assert.IsNull(f.Alias);
         }
         public void Criar_Field_Com_Alias()
         {
             var f = new Field(new Table("users"), "nome").As("nome_do_usuario");
-            Assert.AreEqual("users.nome AS nome_do_usuario", f.ToSql());
+            Assert.AreEqual("users.nome AS nome_do_usuario", f.AsProject());
             Assert.AreEqual("users.nome", f.Project);
             Assert.NotNull(f.Alias);
         }

FluentSql.Test/ComplexQuery.cs

             var cursos = new Table("cursos");
             alunos.Project(alunos.All, cursos["nome"])
                 .Join(cursos)
-                .On(alunos["curso_id"] == cursos["curso_id"]);
-            string sql = "SELECT alunos.*, cursos.nome FROM alunos JOIN cursos ON alunos.curso_id = cursos.curso_id";
+                .On(alunos["curso_id"] == cursos["id"]);
+            string sql = "SELECT alunos.*, cursos.nome FROM alunos JOIN cursos ON alunos.curso_id = cursos.id";
             Assert.AreEqual(sql, alunos.ToSql());
         }
 
         public void Usar_Function_Count_Com_Alias()
         {
             var users = new Table("users");
-            users.Project(Func.Count(users["ativo"]).As("count_usuarios_ativos"));
+            users.Project(F.Count(users["ativo"]).As("count_usuarios_ativos"));
             string sql_expected = "SELECT COUNT(users.ativo) AS count_usuarios_ativos FROM users";
             Assert.AreEqual(sql_expected, users.ToSql());
         }
         {
             var vendas = new Table("vendas", "v");
             var items_venda = new Table("items_venda", "i");
-            vendas.Project(Func.Sum(items_venda["valor"]).As("sum_items_venda_valor"))
+            vendas.Project(F.Sum(items_venda["valor"]).As("sum_items_venda_valor"))
                 .Join(items_venda).On(vendas["id"] == items_venda["venda_id"])
                 .Where(vendas["data"] > new DateTime(2011, 1, 1) & items_venda["valor"] > 12 | items_venda["valor"] < 1000);
-            string sql_expected = "SELECT SUM(i.valor) AS sum_items_venda_valor FROM vendas AS v JOIN items_venda AS i ON v.id = i.venda_id WHERE ((v.data > @vendas_data_1) "
+            string sql_expected = "SELECT SUM(i.valor) AS sum_items_venda_valor FROM vendas AS v "
+                +"JOIN items_venda AS i ON v.id = i.venda_id WHERE ((v.data > @vendas_data_1) "
                 +"AND (i.valor > @items_venda_valor_1)) OR (i.valor < @items_venda_valor_2)";
             Assert.AreEqual(sql_expected, vendas.ToSql());
         }
         public void Usar_Function_Max()
         {
             var produtos = new Table("produtos");
-            produtos.Project(Func.Max(produtos["preco"]).As("preco_produto"))
+            produtos.Project(F.Max(produtos["preco"]).As("preco_produto"))
                 .Project(produtos["descricao"])
                 .Where(produtos["descricao"] != null);
             string sql_expected = "SELECT MAX(produtos.preco) AS preco_produto, produtos.descricao FROM produtos "
         public void Usar_Function_Sum_Com_Having()
         {
             var sales = new Table("sales");
-            sales.Project(sales["DeptID"], Func.Sum(sales["SaleAmount"]))
+            sales.Project(sales["DeptID"], F.Sum(sales["SaleAmount"]))
                 .Where(sales["SaleDate"] == new DateTime(2000, 1, 1))
                 .GroupBy(sales["DeptID"])
-                .Having(Func.Sum(sales["SaleAmount"]) > 1000 | Func.Sum(sales["SaleAmount"]) < 2000);
+                .Having(F.Sum(sales["SaleAmount"]) > 1000 | F.Sum(sales["SaleAmount"]) < 2000);
             string sql_expected = "SELECT sales.DeptID, SUM(sales.SaleAmount) FROM sales WHERE sales.SaleDate = @sales_SaleDate_1 "
-                +"GROUP BY sales.DeptID HAVING (SUM(sales.SaleAmount) > @sales_sum_SaleAmount_1) OR (SUM(sales.SaleAmount) < @sales_sum_SaleAmount_2)";
+                +"GROUP BY sales.DeptID HAVING (SUM(sales.SaleAmount) > @sales_sum_SaleAmount_1) "
+            +"OR (SUM(sales.SaleAmount) < @sales_sum_SaleAmount_2)";
             Assert.AreEqual(sql_expected, sales.ToSql());
-            WriteParams(sales);
         }
 
         [Test]
         {
             var employee = new Table("employee");
             var department = new Table("department");
-            employee.Project(employee["DepartmentName"], Func.Count(employee.All))
+            employee.Project(employee["DepartmentName"], F.Count(employee.All))
                 .Join(department).On(employee["DepartmentID"] == department["DepartmentID"])
                 .GroupBy(department["DepartmentName"])
-                .Having(Func.Count(employee.All) > 1);
+                .Having(F.Count(employee.All) > 1);
             string sql_expected = "SELECT employee.DepartmentName, COUNT(employee.*) FROM employee JOIN department ON " +
-                "employee.DepartmentID = department.DepartmentID GROUP BY department.DepartmentName HAVING COUNT(employee.*) > @employee_count_*_1";
+                "employee.DepartmentID = department.DepartmentID GROUP BY department.DepartmentName HAVING COUNT(employee.*)"+
+            " > @employee_count_*_1";
             Assert.AreEqual(sql_expected, employee.ToSql());
         }
 
             Assert.AreEqual(sql_expected, groups.ToSql());
         }
 
+        [Test]
+        public void Consulta_Com_Order_By()
+        {
+            var users = new Table("users");
+            users.Project(users["name"], users["password"])
+                .Where(users["active"] == true)
+                .OrderBy(users["created_at"].Desc);
+            string sql_expected = "SELECT users.name, users.password FROM users WHERE users.active = @users_active_1 "
+                +"ORDER BY users.created_at DESC";
+            Assert.AreEqual(sql_expected, users.ToSql());
+        }
+
         public void WriteParams(ITable t)
         {
             Console.WriteLine("Params FROM {0}", t.Name);

FluentSql.Test/QueryInsert.cs

         {
             ITable users = new Table("users");
             users.Insert(new { nome = "george", data_nascimento = new DateTime(1989, 8, 22), sexo = "M" });
-            string sql_expected = "INSERT INTO users(nome, data_nascimento, sexo) VALUES(@users_nome_1, @users_data_nascimento_1, @users_sexo_1)";
+            string sql_expected = "INSERT INTO users(nome, data_nascimento, sexo) "+
+                "VALUES(@users_nome_1, @users_data_nascimento_1, @users_sexo_1)";
             Assert.AreEqual(sql_expected, users.ToSql());
         }
 
             hs.Add("sexo", "M");
             var t_users = new Table("users");
             t_users.Insert(hs);
-            string sql_expected = "INSERT INTO users(data_nascimento, nome, sexo) VALUES(@users_data_nascimento_1, @users_nome_1, @users_sexo_1)";
+            string sql_expected = "INSERT INTO users(data_nascimento, nome, sexo) "
+                                    +"VALUES(@users_data_nascimento_1, @users_nome_1, @users_sexo_1)";
             Assert.AreEqual(sql_expected, t_users.ToSql());
         }
 
         public void Insert_Com_Valor_Nulo()
         {
             var users = new Table("users");
-            Hashtable hs = new Hashtable();
-            hs.Add("nome", "george");
-            hs.Add("idade", null);
-            users.Insert(hs);
+            users.Insert(new { nome="george", idade=Utils.NULL });
             string sql_expected = "INSERT INTO users(nome, idade) VALUES(@users_nome_1, NULL)";
             Assert.AreEqual(sql_expected, users.ToSql());
         }

FluentSql.Test/QueryUpdate.cs

         }
 
         [Test]
+        public void Update_Com_Where_E_Valor_Nulo()
+        {
+            var users = new Table("users");
+            users.Where(users["nome"] != null)
+                .Update(new { idade = Utils.NULL });
+            string sql_expected = "UPDATE users SET idade=NULL WHERE users.nome IS NOT NULL";
+            Assert.AreEqual(sql_expected, users.ToSql());
+        }
+
+        [Test]
         public void Update_Com_Where_E_Hashtable()
         {
             var users = new Table("users");

FluentSql/Aggregates/Aggregate.cs

             return string.Format("{0}({1})", this.GetType().Name.ToUpper(), Agg);
         }
 
-        public string ToSql()
+        public string AsProject()
         {
             if (!string.IsNullOrEmpty(Alias))
             {

FluentSql/Aggregates/IAggregate.cs

 
 namespace FluentSql.Aggregates
 {
-    public interface IAggregate : IProjection
+    public interface IAggregate : IProject
     {
         IAggregate As(string alias);
     }

FluentSql/Clause/GroupBy.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace FluentSql.Clause
-{
-    public class GroupBy : IClause
-    {
-        private Field _field;
-        public GroupBy(Field field)
-        {
-            _field = field;
-        }
-
-        #region IClause Members
-
-        public string ToSql()
-        {
-            return string.Format("{0}", this._field.ToSql());
-        }
-
-        #endregion
-    }
-}

FluentSql/Clause/IGroup.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FluentSql.Clause
+{
+    public interface IGroup
+    {
+        string AsGroup();
+    }
+}

FluentSql/Clause/IOrder.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FluentSql.Clause
+{
+    public interface IOrder
+    {
+        string AsOrder();
+        IOrder Asc { get; }
+        IOrder Desc { get; }
+        TypeOrder Order { get; }
+    }
+}

FluentSql/Clause/TypeOrder.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FluentSql.Clause
+{
+    public enum TypeOrder
+    {
+        Asc,
+        Desc
+    }
+}

FluentSql/Command/Delete.cs

             return String.Format("DELETE FROM {0}{1}", Table.Name, BuildWhere());
         }
 
-        public ICommand Project(params IProjection[] projects)
+        public ICommand Project(params IProject[] projects)
         {
             throw new NotSupportedException("Clause don't supported by command.");
         }
             return this;
         }
 
-        public ICommand GroupBy(Field field)
+        public ICommand GroupBy(params IGroup[] groups)
         {
             throw new NotSupportedException("Clause don't supported by command.");
         }
             return string.Empty;
         }
         #endregion
+
+        #region ICommand Members
+
+
+        public ICommand OrderBy(params IOrder[] order)
+        {
+            throw new NotSupportedException("Clause don't supported by command.");
+        }
+
+        #endregion
     }
 }

FluentSql/Command/ICommand.cs

     public interface ICommand
     {
         string ToSql();
-        ICommand Project(params IProjection[] fields);
+        ICommand Project(params IProject[] fields);
         IJoin Join(ITable table);
         IJoin LeftJoin(ITable table);
         IJoin RightJoin(ITable table);
         IJoin InnerJoin(ITable table);
         ICommand Where(IExpression expression);
-        ICommand GroupBy(Field field);
+        ICommand OrderBy(params IOrder[] orders);
+        ICommand GroupBy(params IGroup[] groups);
         ICommand Having(IExpression expression);
         ICommand Count();
         ICommand Values(object values);

FluentSql/Command/Insert.cs

         public ITable Table { get; set; }
         public ICommand Values(object values)
         {
-            IDictionary<string, object> keyvalue = Utils.Params.ObjectToDicionary(values);
+            IDictionary<string, object> keyvalue = Utils.ObjectToDicionary(values);
             foreach (KeyValuePair<string, object> kvp in keyvalue)
             {
                 if (kvp.Value != null)
             return string.Format("INSERT INTO {0}({1}) VALUES({2})", Table.Name, BuildFields(), BuildValues());
         }
 
-        public ICommand Project(params IProjection[] projects)
-        {
-            throw new NotSupportedException("Clause don't supported by command.");
-        }
-
-        public ICommand Project(IAggregate aggregate)
+        public ICommand Project(params IProject[] projects)
         {
             throw new NotSupportedException("Clause don't supported by command.");
         }
             throw new NotSupportedException("Clause don't supported by command.");
         }
 
-        public ICommand GroupBy(Field field)
+        public ICommand GroupBy(params IGroup[] groups)
         {
             throw new NotSupportedException("Clause don't supported by command.");
         }
         }
 
         #endregion
+
+        #region ICommand Members
+
+        public ICommand OrderBy(params IOrder[] order)
+        {
+            throw new NotSupportedException("Clause don't supported by command.");
+        }
+
+        #endregion
     }
 }

FluentSql/Command/Select.cs

         public Select(ITable table)
         {
             this.Table = table;
-            this.Projects = new List<IProjection>();
+            this.Projects = new List<IProject>();
             this.Joins = new List<IJoin>();
             this.Wheres = new List<IExpression>();
-            this.GroupBys = new List<GroupBy>();
+            this.Orders = new List<IOrder>();
+            this.GroupBys = new List<IGroup>();
             this.Havings = new List<IExpression>();
             this._Count = false;
             this._Top = 0;
         }
 
         #region ICommand Members
-        public IList<IProjection> Projects { get; set; }
+        public IList<IProject> Projects { get; set; }
         public IList<IJoin> Joins { get; set; }
         public IList<IExpression> Wheres { get; set; }
-        public IList<GroupBy> GroupBys { get; set; }
+        public IList<IOrder> Orders { get; set; }
+        public IList<IGroup> GroupBys { get; set; }
         public IList<IExpression> Havings { get; set; }
         public ITable Table { get; set; }
         public bool _Count { get; set; }
         public int _Top { get; set; }
+        
         public string ToSql()
         {
-            return String.Format("SELECT {0}{1} {2}{3}{4}{5}{6}", BuildTop(), BuildProject(), BuildFrom(), BuildJoin(), BuildWhere(), BuildGroupBy(), BuildHaving());
+            return String.Format("SELECT {0}{1} {2}{3}{4}{5}{6}{7}", BuildTop(), BuildProject(), 
+                BuildFrom(), BuildJoin(), BuildWhere(), BuildOrderBy(), BuildGroupBy(), BuildHaving());
         }
 
-        public ICommand Project(params IProjection[] projects)
+        public ICommand Project(params IProject[] projects)
         {
             foreach (var p in projects)
             {
             return this;
         }
 
-        public ICommand GroupBy(Field field)
+        public ICommand GroupBy(params IGroup[] groups)
         {
-            GroupBys.Add(new GroupBy(field));
+            foreach (IGroup g in groups)
+            {
+                GroupBys.Add(g);    
+            }
             return this;
         }
 
             {
                 return "*";
             }
-            return String.Join(", ", (from f in Projects select f.ToSql()).ToArray());
+            return String.Join(", ", (from f in Projects select f.AsProject()).ToArray());
         }
 
         private string BuildJoin()
             return string.Empty;
         }
 
+        public string BuildOrderBy()
+        {
+            if (Orders.Count > 0)
+            {
+                return " ORDER BY " + string.Join(" AND ", (from o in Orders select o.AsOrder()).ToArray());
+            }
+            return string.Empty;
+        }
+
         private string BuildGroupBy()
         {
             if (GroupBys.Count > 0)
             {
-                return " GROUP BY " + String.Join(", ", (from g in GroupBys select g.ToSql()).ToArray());
+                return " GROUP BY " + String.Join(", ", (from g in GroupBys select g.AsGroup()).ToArray());
             }
             return string.Empty;
         }
             return string.Empty;
         }
         #endregion
+
+        #region ICommand Members
+
+        public ICommand OrderBy(params IOrder[] orders)
+        {
+            foreach (IOrder order in orders)
+            {
+                Orders.Add(order);
+            }
+            return this;
+        }
+
+        #endregion
     }
 }

FluentSql/Command/Update.cs

 
         #region ICommand Members
 
-        public ICommand Project(params IProjection[] projects)
+        public ICommand Project(params IProject[] projects)
         {
             throw new NotSupportedException("Clause don't supported by command.");
         }
 
         public ICommand Values(object values)
         {
-            IDictionary<string, object> keyvalue = Utils.Params.ObjectToDicionary(values);
+            IDictionary<string, object> keyvalue = Utils.ObjectToDicionary(values);
             foreach (KeyValuePair<string, object> kvp in keyvalue)
             {
                 if (kvp.Value != null)
             return this;
         }
 
-        public ICommand GroupBy(Field field)
+        public ICommand GroupBy(params IGroup[] groups)
         {
             throw new NotSupportedException("Clause don't supported by command.");
         }
         {
             return String.Format("UPDATE {0} SET {1}{2}", this.Table.Name, BuildValues(), BuildWhere());
         }
+
+        #region ICommand Members
+
+
+        public ICommand OrderBy(params IOrder[] order)
+        {
+            throw new NotSupportedException("Clause don't supported by command.");
+        }
+
+        #endregion
     }
 }
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using FluentSql.Aggregates;
+
+namespace FluentSql
+{
+    public static class F
+    {
+        public static Aggregate Count(Field aggregate)
+        {
+            return new Count(aggregate);
+        }
+
+        public static Aggregate Sum(Field aggregate)
+        {
+            return new Sum(aggregate);
+        }
+
+        public static Aggregate Avg(Field aggregate)
+        {
+            return new Avg(aggregate);
+        }
+
+        public static Aggregate Min(Field aggregate)
+        {
+            return new Min(aggregate);
+        }
+
+        public static Aggregate Max(Field aggregate)
+        {
+            return new Max(aggregate);
+        }
+    }
+}

FluentSql/Field.cs

 using System.Linq;
 using System.Text;
 using FluentSql.Expressions;
+using FluentSql.Clause;
 
 namespace FluentSql
 {
-    public class Field : IProjection, IStatement
+    public class Field : IProject, IStatement, IOrder, IGroup
     {
         public Field(ITable table, string name)
         {
             }
         }
 
-        public string ToSql()
+        public string AsProject()
         {
             if (!string.IsNullOrEmpty(this.Alias))
             {
         }
 
         #endregion
+        
+        
 
         #region override operators
 
         }
 
         #endregion
+
+        #region IOrder Members
+
+        public string AsOrder()
+        {
+            return string.Format("{0}{1}", this.Project, this.Order == TypeOrder.Desc ? " DESC" : "");
+        }
+
+        public IOrder Asc
+        {
+            get 
+            {
+                this.Order = TypeOrder.Asc;
+                return this;
+            }
+        }
+
+        public IOrder Desc
+        {
+            get 
+            {
+                this.Order = TypeOrder.Desc;
+                return this;
+            }
+        }
+
+        public TypeOrder Order
+        {
+            get;
+            private set;
+        }
+
+        #endregion
+
+        #region IGroup Members
+
+        public string AsGroup()
+        {
+            return this.Project;
+        }
+
+        #endregion
     }
 }

FluentSql/FluentSql.csproj

     <Compile Include="Aggregates\Max.cs" />
     <Compile Include="Aggregates\Min.cs" />
     <Compile Include="Aggregates\Sum.cs" />
-    <Compile Include="Clause\GroupBy.cs" />
     <Compile Include="Clause\IClause.cs" />
+    <Compile Include="Clause\IGroup.cs" />
     <Compile Include="Clause\IJoin.cs" />
     <Compile Include="Clause\InnerJoin.cs" />
+    <Compile Include="Clause\IOrder.cs" />
     <Compile Include="Clause\Join.cs" />
     <Compile Include="Clause\JoinBase.cs" />
     <Compile Include="Clause\LeftJoin.cs" />
     <Compile Include="Clause\RightJoin.cs" />
+    <Compile Include="Clause\TypeOrder.cs" />
     <Compile Include="Command\Delete.cs" />
     <Compile Include="Command\Select.cs" />
     <Compile Include="Command\Update.cs" />
     <Compile Include="Field.cs" />
     <Compile Include="Command\ICommand.cs" />
     <Compile Include="Command\Insert.cs" />
-    <Compile Include="Func.cs" />
-    <Compile Include="IProjection.cs" />
+    <Compile Include="F.cs" />
+    <Compile Include="IProject.cs" />
     <Compile Include="ITable.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="Table.cs" />
-    <Compile Include="Utils\Params.cs" />
+    <Compile Include="Utils.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 

FluentSql/Func.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using FluentSql.Aggregates;
-
-namespace FluentSql
-{
-    public static class Func
-    {
-        public static Aggregate Count(Field aggregate)
-        {
-            return new Count(aggregate);
-        }
-
-        public static Aggregate Sum(Field aggregate)
-        {
-            return new Sum(aggregate);
-        }
-
-        public static Aggregate Avg(Field aggregate)
-        {
-            return new Avg(aggregate);
-        }
-
-        public static Aggregate Min(Field aggregate)
-        {
-            return new Min(aggregate);
-        }
-
-        public static Aggregate Max(Field aggregate)
-        {
-            return new Max(aggregate);
-        }
-    }
-}

FluentSql/IProject.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace FluentSql
+{
+    public interface IProject
+    {
+        string AsProject();
+    }
+}

FluentSql/IProjection.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-
-namespace FluentSql
-{
-    public interface IProjection
-    {
-        string ToSql();
-    }
-}

FluentSql/ITable.cs

         string AddParam(string key, object obj);
         Hashtable Params { get; }
         void Clear();
-        ITable Project(params IProjection[] projects);
+        ITable Project(params IProject[] projects);
         IJoin Join(ITable table);
         IJoin LeftJoin(ITable table);
         IJoin RightJoin(ITable table);
         IJoin InnerJoin(ITable table);
         ITable Where(IExpression expression);
-        ITable GroupBy(Field field);
+        ITable OrderBy(params IOrder[] order);
+        ITable GroupBy(params IGroup[] groups);
         ITable Having(IExpression expression);
         ITable Count();
         ITable Top(int number);

FluentSql/Table.cs

         #endregion
 
         #region ITable members
-        public ITable Project(params IProjection[] projects)
+        public ITable Project(params IProject[] projects)
         {
             _command.Project(projects);
             return this;
             return this;
         }
 
-        public ITable GroupBy(Field field)
+        public ITable OrderBy(params IOrder[] order)
         {
-            _command.GroupBy(field);
+            _command.OrderBy(order);
+            return this;
+        }
+
+        public ITable GroupBy(params IGroup[] groups)
+        {
+            _command.GroupBy(groups);
             return this;
         }
 

FluentSql/Utils.cs

+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Reflection;
+using System.ComponentModel;
+using System.Collections;
+
+namespace FluentSql
+{
+    public static class Utils
+    {
+        internal static IDictionary<string, object> ObjectToDicionary(object o)
+        {
+            var result = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
+            if (o == null)
+            {
+                return result;
+            }
+            if (o is Hashtable)
+            {
+                foreach (DictionaryEntry de in (Hashtable)o)
+                {
+                    result.Add(de.Key.ToString(), de.Value);
+                }
+            }
+            else
+            {
+                foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(o))
+                {
+                    result.Add(prop.Name, prop.GetValue(o));
+                }
+            }
+            
+            return result;
+        }
+
+        public static void AddFrom(this Hashtable self, Hashtable other)
+        {
+            foreach (DictionaryEntry de in other)
+            {
+                self.Add(de.Key, de.Value);
+            }
+        }
+
+        public const object NULL = null;
+    }
+}

FluentSql/Utils/Params.cs

-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Reflection;
-using System.ComponentModel;
-using System.Collections;
-
-namespace FluentSql.Utils
-{
-    internal class Params
-    {
-        public static IDictionary<string, object> ObjectToDicionary(object o)
-        {
-            var result = new Dictionary<string, object>(StringComparer.InvariantCultureIgnoreCase);
-            if (o == null)
-            {
-                return result;
-            }
-            if (o is Hashtable)
-            {
-                foreach (DictionaryEntry de in (Hashtable)o)
-                {
-                    result.Add(de.Key.ToString(), de.Value);
-                }
-            }
-            else
-            {
-                foreach (PropertyDescriptor prop in TypeDescriptor.GetProperties(o))
-                {
-                    result.Add(prop.Name, prop.GetValue(o));
-                }
-            }
-            
-            return result;
-        }
-    }
-}