public static DataTable ConvertHastTableToDataTable(System.Collections.Hashtable hashtable) { var dt1 = new DataTable(hashtable.GetType( ).Name); int inti = 1; dt1.Columns.Add("رديف"); dt1.Columns.Add("شماره رنگ"); dt1.Columns.Add("تعداد تکرار"); dt1.Columns.Add("رنگ"); IDictionaryEnumerator enumerator = hashtable.GetEnumerator( ); while (enumerator.MoveNext( )) { dt1.Rows.Add(inti, enumerator.Key, enumerator.Value, ""); ++inti; } return(dt1); }
private static void arr2xml(XmlWriter xml, Hashtable data) { string substr = ""; int status = 0; if (data != null && data.GetType().ToString() == "System.Collections.Hashtable") { foreach (DictionaryEntry item in data) { if (item.Value.GetType().ToString() == "System.Collections.Hashtable") { xml.WriteStartElement(item.Key.ToString()); Hashtable v2 = item.Value as Hashtable; OpenPayU.arr2xml(xml, v2); xml.WriteEndElement(); status = 0; continue; } else { status = 0; substr = item.Value.GetType().ToString(); if (substr.Length > 30) substr = item.Value.GetType().ToString().Substring(0, 32); if (substr == "System.Collections.Generic.Stack") { xml.WriteStartElement(item.Key.ToString()); status = 1; Stack<Hashtable> v3 = item.Value as Stack<Hashtable>; foreach (Hashtable item2 in v3) { Hashtable v4 = item2 as Hashtable; OpenPayU.arr2xml(xml, v4); } xml.WriteEndElement(); continue; } } if (status == 0) xml.WriteElementString(item.Key.ToString(), item.Value.ToString()); status = 0; } } }
public void CreateTryGetValueDelegateWrapsNonGenericDictionaries() { // Arrange object dictionary = new Hashtable() { { "foo", 42 } }; // Act TryGetValueDelegate d = TypeHelpers.CreateTryGetValueDelegate(dictionary.GetType()); object fooValue; bool fooIsFound = d(dictionary, "foo", out fooValue); object barValue; bool barIsFound = d(dictionary, "bar", out barValue); // Assert Assert.True(fooIsFound); Assert.Equal(42, fooValue); Assert.False(barIsFound); Assert.Null(barValue); }
public void CreatingHashes() { var hash = new Hashtable (); Assert.Equals (typeof(System.Collections.Hashtable), hash.GetType ()); Assert.Equals (FILL_ME_IN, hash.Count); }
public void CreatingHashes() { var hash = new Hashtable (); Assert.AreEqual(typeof(System.Collections.Hashtable), hash.GetType ()); Assert.AreEqual(0, hash.Count); }
// -------------------------------------------------------------------------- private static void ResizeArray(ref Hashtable[] oldArray, int newSize) { int oldSize = oldArray.Length; System.Type elementType = oldArray.GetType().GetElementType(); Hashtable[] newArray = (Hashtable[])System.Array.CreateInstance(elementType, newSize); int preserveLength = System.Math.Min(oldSize, newSize); if (preserveLength > 0) System.Array.Copy(oldArray, newArray, preserveLength); oldArray = newArray; }