From: iSazonov Date: Tue, 28 Aug 2018 14:32:50 +0000 (+0500) Subject: Add null check in Count property X-Git-Tag: submit/tizen/20210909.063632~11031^2~3620^2~6 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=cf8d616c9e39ad189fd62e022347b21716b5c591;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Add null check in Count property Commit migrated from https://github.com/dotnet/corefx/commit/a7c75ef354acc0325028fee9cc570e17a8e50a8b --- diff --git a/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/OrderedDictionary.cs b/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/OrderedDictionary.cs index 04f460a..c4b38fb 100644 --- a/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/OrderedDictionary.cs +++ b/src/libraries/System.Collections.Specialized/src/System/Collections/Specialized/OrderedDictionary.cs @@ -15,7 +15,7 @@ namespace System.Collections.Specialized /// OrderedDictionary is used by the ParameterCollection because MSAccess relies on ordering of /// parameters, while almost all other DBs do not. DataKeyArray also uses it so /// DataKeys can be retrieved by either their name or their index. - /// + /// /// OrderedDictionary implements IDeserializationCallback because it needs to have the /// contained ArrayList and Hashtable deserialized before it tries to get its count and objects. /// @@ -69,7 +69,7 @@ namespace System.Collections.Specialized protected OrderedDictionary(SerializationInfo info, StreamingContext context) { // We can't do anything with the keys and values until the entire graph has been deserialized - // and getting Counts and objects won't fail. For the time being, we'll just cache this. + // and getting Counts and objects won't fail. For the time being, we'll just cache this. // The graph is not valid until OnDeserialization has been called. _siInfo = info; } @@ -81,7 +81,11 @@ namespace System.Collections.Specialized { get { - return objectsArray.Count; + if (_objectsArray == null) + { + return 0; + } + return _objectsArray.Count; } } @@ -377,7 +381,7 @@ namespace System.Collections.Specialized } #endregion -#region ISerializable implementation +#region ISerializable implementation public virtual void GetObjectData(SerializationInfo info, StreamingContext context) { if (info == null) @@ -399,7 +403,7 @@ namespace System.Collections.Specialized void IDeserializationCallback.OnDeserialization(object sender) { OnDeserialization(sender); } - + protected virtual void OnDeserialization(object sender) { if (_siInfo == null)