예제 #1
0
        //Select multiple statement
        public List <CloneableDictionary <string, string> > SelectMultiple(string query)
        {
            var lol = new List <CloneableDictionary <string, string> >();

            if (this.OpenConnection() == true)
            {
                MySqlCommand    cmd        = new MySqlCommand(query, connection);
                MySqlDataReader dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    var listOfStrings = new CloneableDictionary <string, string>();
                    int columns       = dataReader.FieldCount;
                    for (int x = 0; x < columns; x++)
                    {
                        listOfStrings.Add(dataReader.GetName(x).ToLower(), dataReader[x].ToString());
                    }

                    lol.Add(listOfStrings.Clone());
                }
                dataReader.Close();
                this.CloseConnection();

                return(lol);
            }
            else
            {
                return(lol);
            }
        }
예제 #2
0
        public void CloneableDictionary_Clone()
        {
            CloneableDictionary<int, string> source
                = new CloneableDictionary<int, string>
                {
                    { 1, "one" },
                    { 2, "two" },
                    { 3, "three" }
                };

            CloneableDictionary<int, string> clone
                = (CloneableDictionary<int, string>) source.Clone();

            Assert.AreEqual(source.Count, clone.Count);
            var keys = source.Keys;
            foreach (int key in keys)
            {
                Assert.AreEqual(source[key], clone[key]);
            }
        }
예제 #3
0
        public void Test_Cloneable_Dictionary()
        {
            Stopwatch sw = new Stopwatch();
            CloneableDictionary <string, Person> cDict = new CloneableDictionary <string, Person>();

            for (int i = 0; i <= 10000; i++)
            {
                Person p = new Person(i, "Horst" + i);
                cDict.Add(i + p.Name, p);
            }

            Assert.Equal(10001, cDict.Count);
            CloneableDictionary <string, Person> clonedDict = cDict.Clone();

            Assert.NotEqual(clonedDict[100].Item2, cDict[100].Item2);
            Assert.Equal(clonedDict[100].Item2.ID, cDict[100].Item2.ID);
            Assert.Equal(clonedDict[100].Item2.Name, cDict[100].Item2.Name);
            Assert.Equal(clonedDict[100].Item2.Adress, cDict[100].Item2.Adress);

            DictionaryTests(cDict);
            DictionaryTests(clonedDict);
        }
예제 #4
0
        public void Test_Performance()
        {
            Stopwatch sw = new Stopwatch();
            IDictionary <string, Person> personDict = new Dictionary <string, Person>();

            for (int i = 0; i <= 10000; i++)
            {
                Person p = new Person(i, "Horst" + i);
                personDict.Add(i + p.Name, p);
            }

            personDict.Clone();
            sw.Start();
            personDict.Clone();
            sw.Stop();

            Console.WriteLine("personDict: " + sw.ElapsedMilliseconds);

            IList <KeyValuePair <string, Person> > personListKeyValue = personDict.ToList();

            personListKeyValue.Clone();
            sw.Restart();
            personListKeyValue.Clone();
            sw.Stop();

            Console.WriteLine("personListKeyValue: " + sw.ElapsedMilliseconds);

            IList <Person> personList = personDict.Values.ToList();

            personList.Clone();
            sw.Restart();
            personList.Clone();
            sw.Stop();

            Console.WriteLine("personList: " + sw.ElapsedMilliseconds);

            IList <Tuple <string, Person> > personTupleList = personDict.Select(p => Tuple.Create(p.Key, p.Value)).ToList();

            personTupleList.Clone();
            sw.Restart();
            personTupleList.Clone();
            sw.Stop();

            Console.WriteLine("personTupleList: " + sw.ElapsedMilliseconds);

            ICollection <Tuple <string, Person> > personTupleCollection = personDict.Select(p => Tuple.Create(p.Key, p.Value)).ToList();

            personTupleCollection.Clone();
            sw.Restart();
            personTupleCollection.Clone();
            sw.Stop();

            Console.WriteLine("personTupleCollection: " + sw.ElapsedMilliseconds);

            CloneableDictionary <string, Person> cDict = new CloneableDictionary <string, Person>(personDict);
            int count = cDict.Count;

            Assert.Equal(10001, count);

            cDict.Clone();
            sw.Restart();
            cDict.Clone();
            sw.Stop();

            Console.WriteLine("CloneableDictionary: " + sw.ElapsedMilliseconds);
        }
예제 #5
0
        //Select multiple statement
        public List<CloneableDictionary<string, string>> SelectMultiple(string query)
        {
            var lol = new List<CloneableDictionary<string, string>>();

            if (this.OpenConnection() == true)
            {
                MySqlCommand cmd = new MySqlCommand(query, connection);
                MySqlDataReader dataReader = cmd.ExecuteReader();

                while (dataReader.Read())
                {
                    var listOfStrings = new CloneableDictionary<string, string>();
                    int columns = dataReader.FieldCount;
                    for (int x = 0; x < columns; x++)
                    {
                        listOfStrings.Add(dataReader.GetName(x).ToLower(), dataReader[x].ToString());
                    }

                    lol.Add(listOfStrings.Clone());

                }
                dataReader.Close();
                this.CloseConnection();

                return lol;
            }
            else
            {
                return lol;
            }

        }