提交 872c7d9a 编写于 作者: M Marek Habersack

[configuration] Part of fix for bug #579837. CommaDelimitedStringCollection...

[configuration] Part of fix for bug #579837. CommaDelimitedStringCollection must properly note that it was modified.

When one manipulates the collection as an instance of StringCollection, the 'modified' field will not
be set (Add, Remove etc. from the underlying StringCollection type will be used). To work around it
a check has to be performed in IsModified whether the contents of the collection changed. It is done
by comparing string hash codes of the original vs current string.
CommaDelimitedStringCollectionConverter forces string hash code update on the new collection, so that IsModified
works correctly on collections converted from comma-delimited strings.
上级 a308e3e6
......@@ -39,9 +39,19 @@ namespace System.Configuration {
bool modified;
bool readOnly;
int originalStringHash = 0;
public bool IsModified {
get { return modified; }
get {
if (modified)
return true;
string str = ToString ();
if (str == null)
return false;
return str.GetHashCode () != originalStringHash;
}
}
public new bool IsReadOnly {
......@@ -89,6 +99,7 @@ namespace System.Configuration {
CopyTo (contents, 0);
col.AddRange (contents);
col.originalStringHash = originalStringHash;
return col;
}
......@@ -125,6 +136,15 @@ namespace System.Configuration {
return String.Join (",", contents);
}
internal void UpdateStringHash ()
{
string str = ToString ();
if (str == null)
originalStringHash = 0;
else
originalStringHash = str.GetHashCode ();
}
}
}
......
......@@ -48,6 +48,7 @@ namespace System.Configuration
foreach (string datum in datums)
col.Add (datum.Trim());
col.UpdateStringHash ();
return col;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册