Skip to content

Commit

Permalink
Merge pull request dotnet#369 from justinvp/specialized_readonly
Browse files Browse the repository at this point in the history
Make read-only fields readonly
  • Loading branch information
stephentoub committed Jan 8, 2015
2 parents 30b7f16 + f999396 commit 616cf19
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class HybridDictionary : IDictionary
// Instance variables. This keeps the HybridDictionary very light-weight when empty
private ListDictionary _list;
private Hashtable _hashtable;
private bool _caseInsensitive;
private readonly bool _caseInsensitive;

public HybridDictionary()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class ListDictionary : IDictionary
private DictionaryNode _head;
private int _version;
private int _count;
private IComparer _comparer;
private readonly IComparer _comparer;
private Object _syncRoot;

public ListDictionary()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public abstract class NameObjectCollectionBase : ICollection
private int _version;
private Object _syncRoot;

private static StringComparer s_defaultComparer = CultureInfo.InvariantCulture.CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);
private static readonly StringComparer s_defaultComparer = CultureInfo.InvariantCulture.CompareInfo.GetStringComparer(CompareOptions.IgnoreCase);

/// <devdoc>
/// <para> Creates an empty <see cref='System.Collections.Specialized.NameObjectCollectionBase'/> instance with the default initial capacity and using the default case-insensitive hash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public class OrderedDictionary : IOrderedDictionary
{
private ArrayList _objectsArray;
private Hashtable _objectsTable;
private int _initialCapacity;
private IEqualityComparer _comparer;
private bool _readOnly;
private readonly int _initialCapacity;
private readonly IEqualityComparer _comparer;
private readonly bool _readOnly;
private Object _syncRoot;

public OrderedDictionary() : this(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace System.Collections.Specialized
/// </devdoc>
public class StringCollection : IList
{
private ArrayList _data = new ArrayList();
private readonly ArrayList _data = new ArrayList();

/// <devdoc>
/// <para>Represents the entry at the specified index of the <see cref='System.Collections.Specialized.StringCollection'/>.</para>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class StringDictionary : IEnumerable
// That means using ToLower in each property on this type. Also for backwards
// compatibility, we will be converting strings to lower-case, which has a
// problem for some Georgian alphabets.
internal Hashtable contents = new Hashtable();
private readonly Hashtable _contents = new Hashtable();


/// <devdoc>
Expand All @@ -42,7 +42,7 @@ public virtual int Count
{
get
{
return contents.Count;
return _contents.Count;
}
}

Expand All @@ -55,7 +55,7 @@ public virtual bool IsSynchronized
{
get
{
return contents.IsSynchronized;
return _contents.IsSynchronized;
}
}

Expand All @@ -71,7 +71,7 @@ public virtual string this[string key]
throw new ArgumentNullException("key");
}

return (string)contents[key.ToLowerInvariant()];
return (string)_contents[key.ToLowerInvariant()];
}
set
{
Expand All @@ -80,7 +80,7 @@ public virtual string this[string key]
throw new ArgumentNullException("key");
}

contents[key.ToLowerInvariant()] = value;
_contents[key.ToLowerInvariant()] = value;
}
}

Expand All @@ -91,7 +91,7 @@ public virtual ICollection Keys
{
get
{
return contents.Keys;
return _contents.Keys;
}
}

Expand All @@ -103,7 +103,7 @@ public virtual object SyncRoot
{
get
{
return contents.SyncRoot;
return _contents.SyncRoot;
}
}

Expand All @@ -114,7 +114,7 @@ public virtual ICollection Values
{
get
{
return contents.Values;
return _contents.Values;
}
}

Expand All @@ -128,15 +128,15 @@ public virtual void Add(string key, string value)
throw new ArgumentNullException("key");
}

contents.Add(key.ToLowerInvariant(), value);
_contents.Add(key.ToLowerInvariant(), value);
}

/// <devdoc>
/// <para>Removes all entries from the StringDictionary.</para>
/// </devdoc>
public virtual void Clear()
{
contents.Clear();
_contents.Clear();
}

/// <devdoc>
Expand All @@ -149,15 +149,15 @@ public virtual bool ContainsKey(string key)
throw new ArgumentNullException("key");
}

return contents.ContainsKey(key.ToLowerInvariant());
return _contents.ContainsKey(key.ToLowerInvariant());
}

/// <devdoc>
/// <para>Determines if the StringDictionary contains a specific value.</para>
/// </devdoc>
public virtual bool ContainsValue(string value)
{
return contents.ContainsValue(value);
return _contents.ContainsValue(value);
}

/// <devdoc>
Expand All @@ -166,15 +166,15 @@ public virtual bool ContainsValue(string value)
/// </devdoc>
public virtual void CopyTo(Array array, int index)
{
contents.CopyTo(array, index);
_contents.CopyTo(array, index);
}

/// <devdoc>
/// <para>Returns an enumerator that can iterate through the string dictionary.</para>
/// </devdoc>
public virtual IEnumerator GetEnumerator()
{
return contents.GetEnumerator();
return _contents.GetEnumerator();
}

/// <devdoc>
Expand All @@ -187,7 +187,7 @@ public virtual void Remove(string key)
throw new ArgumentNullException("key");
}

contents.Remove(key.ToLowerInvariant());
_contents.Remove(key.ToLowerInvariant());
}
}
}

0 comments on commit 616cf19

Please sign in to comment.