未验证 提交 a0112cb0 编写于 作者: H Hugh Bellamy 提交者: GitHub

Fix NullReferenceException in XamlType.Equals/XamlType.GetHashCode (#220)

上级 3f665bb0
......@@ -1719,8 +1719,11 @@ public override int GetHashCode()
{
if (IsUnknown)
{
Debug.Assert(_namespaces != null && _namespaces.Count > 0);
int result = _name.GetHashCode() ^ _namespaces[0].GetHashCode();
int result = _name.GetHashCode();
if (_namespaces != null && _namespaces.Count > 0)
{
result ^= _namespaces[0].GetHashCode();
}
if (_typeArguments != null && _typeArguments.Count > 0)
{
foreach (XamlType typeArgument in _typeArguments)
......@@ -1762,11 +1765,20 @@ public bool Equals(XamlType other)
{
if (xamlType2.IsUnknown)
{
Debug.Assert(xamlType1._namespaces != null && xamlType1._namespaces.Count > 0);
Debug.Assert(xamlType2._namespaces != null && xamlType2._namespaces.Count > 0);
if (xamlType1._namespaces != null)
{
if (xamlType2._namespaces == null || xamlType1._namespaces[0] != xamlType2._namespaces[0])
{
return false;
}
}
else if (xamlType2._namespaces != null)
{
return false;
}
return (xamlType1._name == xamlType2._name) &&
(xamlType1._namespaces[0] == xamlType2._namespaces[0]) &&
typeArgumentsAreEqual(xamlType1, xamlType2);
TypeArgumentsAreEqual(xamlType1, xamlType2);
}
return false;
}
......@@ -1785,9 +1797,10 @@ public bool Equals(XamlType other)
return !(xamlType1 == xamlType2);
}
private static bool typeArgumentsAreEqual(XamlType xamlType1, XamlType xamlType2)
private static bool TypeArgumentsAreEqual(XamlType xamlType1, XamlType xamlType2)
{
Debug.Assert(xamlType1.IsUnknown && xamlType2.IsUnknown);
Debug.Assert(xamlType1.IsUnknown);
Debug.Assert(xamlType2.IsUnknown);
if (!xamlType1.IsGeneric)
{
return !xamlType2.IsGeneric;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册