/// <summary>Returns a hash code for the given object, using a hashing algorithm that ignores the case of strings.</summary> /// <returns>A hash code for the given object, using a hashing algorithm that ignores the case of strings.</returns> /// <param name="obj">The <see cref="T:System.Object" /> for which a hash code is to be returned. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="obj" /> is null. </exception> /// <filterpriority>2</filterpriority> /// <PermissionSet> /// <IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Flags="UnmanagedCode" /> /// </PermissionSet> public int GetHashCode(object obj) { if (obj == null) { throw new ArgumentNullException("obj"); } string text = obj as string; if (text == null) { return(obj.GetHashCode()); } int num = 0; if (this.m_text != null && !CaseInsensitiveHashCodeProvider.AreEqual(this.m_text, CultureInfo.InvariantCulture)) { foreach (char c in this.m_text.ToLower(text)) { num = num * 31 + (int)c; } } else { for (int j = 0; j < text.Length; j++) { char c = char.ToLower(text[j], CultureInfo.InvariantCulture); num = num * 31 + (int)c; } } return(num); }
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.CaseInsensitiveHashCodeProvider" /> class using the <see cref="P:System.Threading.Thread.CurrentCulture" /> of the current thread.</summary> public CaseInsensitiveHashCodeProvider() { CultureInfo currentCulture = CultureInfo.CurrentCulture; if (!CaseInsensitiveHashCodeProvider.AreEqual(currentCulture, CultureInfo.InvariantCulture)) { this.m_text = CultureInfo.CurrentCulture.TextInfo; } }
public void Clear () { if (m_InternalHashTable != null) m_InternalHashTable.Clear (); CaseInsensitiveHashCodeProvider HashCodeProvider= new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture); CaseInsensitiveComparer Comparer = new CaseInsensitiveComparer (CultureInfo.InvariantCulture); m_InternalHashTable = new Hashtable (HashCodeProvider, Comparer); }
/// <summary>Initializes a new instance of the <see cref="T:System.Collections.CaseInsensitiveHashCodeProvider" /> class using the specified <see cref="T:System.Globalization.CultureInfo" />.</summary> /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> to use for the new <see cref="T:System.Collections.CaseInsensitiveHashCodeProvider" />. </param> /// <exception cref="T:System.ArgumentNullException"> /// <paramref name="culture" /> is null. </exception> public CaseInsensitiveHashCodeProvider(CultureInfo culture) { if (culture == null) { throw new ArgumentNullException("culture"); } if (!CaseInsensitiveHashCodeProvider.AreEqual(culture, CultureInfo.InvariantCulture)) { this.m_text = culture.TextInfo; } }
public void Clear () { m_DefaultLanguage = Language.English; m_CurrentLanguage = Language.English; m_InstanceCounter = 0; if (m_InternalLanguageHashTable != null) m_InternalLanguageHashTable.Clear (); CaseInsensitiveHashCodeProvider HashCodeProvider= new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture); CaseInsensitiveComparer Comparer = new CaseInsensitiveComparer (CultureInfo.InvariantCulture); m_InternalLanguageHashTable = new Hashtable (HashCodeProvider, Comparer); }
public void DefaultInvariant () { CaseInsensitiveHashCodeProvider cih = new CaseInsensitiveHashCodeProvider ( CultureInfo.InvariantCulture); int h1 = cih.GetHashCode ("Test String"); cih = CaseInsensitiveHashCodeProvider.DefaultInvariant; int h2 = cih.GetHashCode ("Test String"); Assert.AreEqual (h1, h2, "#1"); CaseInsensitiveHashCodeProvider cih1 = CaseInsensitiveHashCodeProvider.DefaultInvariant; CaseInsensitiveHashCodeProvider cih2 = CaseInsensitiveHashCodeProvider.DefaultInvariant; Assert.IsTrue (object.ReferenceEquals (cih1, cih2)); }
public void HashCode () { CaseInsensitiveHashCodeProvider cih = new CaseInsensitiveHashCodeProvider (); int h1 = cih.GetHashCode ("Test String"); int h2 = cih.GetHashCode ("test string"); int h3 = cih.GetHashCode ("TEST STRING"); Assert.IsTrue (h1 == h2, "Mixed Case != lower case"); Assert.IsTrue (h1 == h3, "Mixed Case != UPPER CASE"); h1 = cih.GetHashCode ("one"); h2 = cih.GetHashCode ("another"); // Actually this is quite possible. Assert.IsFalse (h1 == h2); }
public DocumentDirective (string name, IDictionary properties, int key) { this.name = name; this.key = key; CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture); CaseInsensitiveComparer comparer = new CaseInsensitiveComparer(CultureInfo.InvariantCulture); this.properties = new Hashtable (provider, comparer); if (properties != null) foreach (DictionaryEntry de in properties) { CheckValidPropertyName (name, (string) de.Key); CheckValidPropertyValue (name, (string)de.Key, (string)de.Value); this.properties.Add (de.Key, de.Value); } }
public void Default () { CaseInsensitiveHashCodeProvider cih = new CaseInsensitiveHashCodeProvider ( CultureInfo.CurrentCulture); int h1 = cih.GetHashCode ("Test String"); cih = CaseInsensitiveHashCodeProvider.Default; int h2 = cih.GetHashCode ("Test String"); Assert.AreEqual (h1, h2, "#1"); Thread.CurrentThread.CurrentCulture = new CultureInfo ("en-US"); CaseInsensitiveHashCodeProvider cih1 = CaseInsensitiveHashCodeProvider.Default; Thread.CurrentThread.CurrentCulture = new CultureInfo ("nl-BE"); CaseInsensitiveHashCodeProvider cih2 = CaseInsensitiveHashCodeProvider.Default; Assert.IsFalse (object.ReferenceEquals (cih1, cih2), "#2"); }
private static void InitHash () { #if (NET_1_1) CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture); CaseInsensitiveComparer comparer = new CaseInsensitiveComparer (CultureInfo.InvariantCulture); _directivesHash = new Hashtable (provider, comparer); // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n)) Hashtable valid_attributes = new Hashtable (provider, comparer); foreach (string att in _tempateAttributes) valid_attributes.Add (att, null); _directivesHash.Add ("CodeTemplate", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in _importAttributes) valid_attributes.Add (att, null); _directivesHash.Add ("Import", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in _assemblyAttributes) valid_attributes.Add (att, null); _directivesHash.Add ("Assembly", valid_attributes); #else _directivesHash = new Hashtable(StringComparer.OrdinalIgnoreCase); // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n)) Hashtable valid_attributes = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (string att in _tempateAttributes) valid_attributes.Add(att, null); _directivesHash.Add("CodeTemplate", valid_attributes); valid_attributes = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (string att in _importAttributes) valid_attributes.Add(att, null); _directivesHash.Add("Import", valid_attributes); valid_attributes = new Hashtable(StringComparer.OrdinalIgnoreCase); foreach (string att in _assemblyAttributes) valid_attributes.Add(att, null); _directivesHash.Add("Assembly", valid_attributes); #endif }
public void SerializationRoundtrip () { CaseInsensitiveHashCodeProvider enus = new CaseInsensitiveHashCodeProvider (new CultureInfo ("en-US")); BinaryFormatter bf = new BinaryFormatter (); MemoryStream ms = new MemoryStream (); bf.Serialize (ms, enus); ms.Position = 0; CaseInsensitiveHashCodeProvider clone = (CaseInsensitiveHashCodeProvider) bf.Deserialize (ms); Assert.AreEqual (enus.GetHashCode (String.Empty), clone.GetHashCode (String.Empty), "GetHashCode(string)"); Assert.AreEqual (enus.GetHashCode (Int32.MinValue), clone.GetHashCode (Int32.MinValue), "GetHashCode(int)"); }
public void Constructor1_Serialization () { CaseInsensitiveHashCodeProvider cihcp = new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture); BinaryFormatter bf = new BinaryFormatter (); MemoryStream ms = new MemoryStream (); bf.Serialize (ms, cihcp); byte[] ser1 = ms.ToArray (); cihcp = CaseInsensitiveHashCodeProvider.DefaultInvariant; ms = new MemoryStream (); bf.Serialize (ms, cihcp); byte[] ser2 = ms.ToArray (); Assert.AreEqual (ser1, ser2, "#1"); }
static private void InitLookupTables () { // Performance arrays s_HttpRequestHeaderNames = new string [40]; s_HttpResponseHeaderNames = new string [30]; // Lookup tables (name -> id) CaseInsensitiveHashCodeProvider hprovider; hprovider = new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture); CaseInsensitiveComparer hcomparer; hcomparer = new CaseInsensitiveComparer (CultureInfo.InvariantCulture); s_HttpRequestHeaderTable = new Hashtable (hprovider, hcomparer); s_HttpResponseHeadersTable = new Hashtable (hprovider, hcomparer); AddHeader (true, true, 0, "Cache-Control"); AddHeader (true, true, 1, "Connection"); AddHeader (true, true, 2, "Date"); AddHeader (true, true, 3, "Keep-Alive"); AddHeader (true, true, 4, "Pragma"); AddHeader (true, true, 5, "Trailer"); AddHeader (true, true, 6, "Transfer-Encoding"); AddHeader (true, true, 7, "Upgrade"); AddHeader (true, true, 8, "Via"); AddHeader (true, true, 9, "Warning"); AddHeader (true, true, 10, "Allow"); AddHeader (true, true, 11, "Content-Length"); AddHeader (true, true, 12, "Content-Type"); AddHeader (true, true, 13, "Content-Encoding"); AddHeader (true, true, 14, "Content-Language"); AddHeader (true, true, 15, "Content-Location"); AddHeader (true, true, 16, "Content-MD5"); AddHeader (true, true, 17, "Content-Range"); AddHeader (true, true, 18, "Expires"); AddHeader (true, true, 19, "Last-Modified"); AddHeader (true, false, 20, "Accept"); AddHeader (true, false, 21, "Accept-Charset"); AddHeader (true, false, 22, "Accept-Encoding"); AddHeader (true, false, 23, "Accept-Language"); AddHeader (true, false, 24, "Authorization"); AddHeader (true, false, 25, "Cookie"); AddHeader (true, false, 26, "Expect"); AddHeader (true, false, 27, "From"); AddHeader (true, false, 28, "Host"); AddHeader (true, false, 29, "If-Match"); AddHeader (true, false, 30, "If-Modified-Since"); AddHeader (true, false, 31, "If-None-Match"); AddHeader (true, false, 32, "If-Range"); AddHeader (true, false, 33, "If-Unmodified-Since"); AddHeader (true, false, 34, "Max-Forwards"); AddHeader (true, false, 35, "Proxy-Authorization"); AddHeader (true, false, 36, "Referer"); AddHeader (true, false, 37, "Range"); AddHeader (true, false, 38, "TE"); AddHeader (true, false, 39, "User-Agent"); AddHeader (false, true, 20, "Accept-Ranges"); AddHeader (false, true, 21, "Age"); AddHeader (false, true, 22, "ETag"); AddHeader (false, true, 23, "Location"); AddHeader (false, true, 24, "Proxy-Authenticate"); AddHeader (false, true, 25, "Retry-After"); AddHeader (false, true, 26, "Server"); AddHeader (false, true, 27, "Set-Cookie"); AddHeader (false, true, 28, "Vary"); AddHeader (false, true, 29, "WWW-Authenticate"); }
private static void InitHash () { CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider (CultureInfo.InvariantCulture); CaseInsensitiveComparer comparer = new CaseInsensitiveComparer (CultureInfo.InvariantCulture); directivesHash = new Hashtable (provider, comparer); // Use Hashtable 'cause is O(1) in Contains (ArrayList is O(n)) Hashtable valid_attributes = new Hashtable (provider, comparer); foreach (string att in page_atts) valid_attributes.Add (att, null); directivesHash.Add ("PAGE", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in control_atts) valid_attributes.Add (att, null); directivesHash.Add ("CONTROL", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in import_atts) valid_attributes.Add (att, null); directivesHash.Add ("IMPORT", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in implements_atts) valid_attributes.Add (att, null); directivesHash.Add ("IMPLEMENTS", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in register_atts) valid_attributes.Add (att, null); directivesHash.Add ("REGISTER", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in assembly_atts) valid_attributes.Add (att, null); directivesHash.Add ("ASSEMBLY", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in outputcache_atts) valid_attributes.Add (att, null); directivesHash.Add ("OUTPUTCACHE", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in reference_atts) valid_attributes.Add (att, null); directivesHash.Add ("REFERENCE", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in webservice_atts) valid_attributes.Add (att, null); directivesHash.Add ("WEBSERVICE", valid_attributes); valid_attributes = new Hashtable (provider, comparer); // same attributes as webservice foreach (string att in webservice_atts) valid_attributes.Add (att, null); directivesHash.Add ("WEBHANDLER", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in application_atts) valid_attributes.Add (att, null); directivesHash.Add ("APPLICATION", valid_attributes); #if NET_2_0 valid_attributes = new Hashtable (provider, comparer); foreach (string att in mastertype_atts) valid_attributes.Add (att, null); directivesHash.Add ("MASTERTYPE", valid_attributes); valid_attributes = new Hashtable (provider, comparer); foreach (string att in control_atts) valid_attributes.Add (att, null); directivesHash.Add ("MASTER", valid_attributes); #endif }
protected virtual IDictionary CreateDictionary(object parent) { #if NET_1_0 CaseInsensitiveHashCodeProvider hcp = new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture); CaseInsensitiveComparer comparer = new CaseInsensitiveComparer(CultureInfo.InvariantCulture); #else CaseInsensitiveHashCodeProvider hcp = CaseInsensitiveHashCodeProvider.DefaultInvariant; CaseInsensitiveComparer comparer = CaseInsensitiveComparer.DefaultInvariant; #endif return parent != null ? new Hashtable((IDictionary) parent, hcp, comparer) : new Hashtable(hcp, comparer); }
private void initDocument (Control parent, DesignerHost host) { System.Diagnostics.Trace.WriteLine ("Creating document..."); if (!(parent is WebFormPage)) throw new NotImplementedException ("Only WebFormsPages can have a document for now"); this.parent = parent; this.host = host; if (!host.Loading) throw new InvalidOperationException ("The document cannot be initialised or loaded unless the host is loading"); CaseInsensitiveHashCodeProvider provider = new CaseInsensitiveHashCodeProvider(CultureInfo.InvariantCulture); CaseInsensitiveComparer comparer = new CaseInsensitiveComparer(CultureInfo.InvariantCulture); directives = new Hashtable (provider, comparer); this.aspParser = new DesignTimeParser (host, this); }