Skip to content

Commit

Permalink
Use default AmbiguousMatchException message where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
jkotas committed Dec 25, 2021
1 parent e69257c commit 61250b4
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2769,7 +2769,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
MethodInfo methodInfo = candidates[j];
if (!System.DefaultBinder.CompareMethodSig(methodInfo, firstCandidate))
{
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
}
}

Expand Down Expand Up @@ -2837,7 +2837,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
{
if (returnType is null)
// if we are here we have no args or property type to select over and we have more than one property with that name
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
}
}

Expand Down Expand Up @@ -2866,7 +2866,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
if ((bindingAttr & eventInfo.BindingFlags) == eventInfo.BindingFlags)
{
if (match != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

match = eventInfo;
}
Expand Down Expand Up @@ -2896,7 +2896,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
if (match != null)
{
if (ReferenceEquals(fieldInfo.DeclaringType, match.DeclaringType))
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

if ((match.DeclaringType!.IsInterface) && (fieldInfo.DeclaringType!.IsInterface))
multipleStaticFieldMatches = true;
Expand All @@ -2908,7 +2908,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
}

if (multipleStaticFieldMatches && match!.DeclaringType!.IsInterface)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

return match;
}
Expand Down Expand Up @@ -2940,7 +2940,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
if (FilterApplyType(iface, bindingAttr, name, false, ns))
{
if (match != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

match = iface;
}
Expand Down Expand Up @@ -2969,7 +2969,7 @@ public override InterfaceMapping GetInterfaceMap([DynamicallyAccessedMembers(Dyn
if (FilterApplyType(nestedType, bindingAttr, name, false, ns))
{
if (match != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

match = nestedType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,6 @@
<data name="MissingMember" xml:space="preserve">
<value>Member not found.</value>
</data>
<data name="Arg_AmbiguousMatchException" xml:space="preserve">
<value>Ambiguous match found.</value>
</data>
<data name="NoMetadataTokenAvailable" xml:space="preserve">
<value>There is no metadata token available for the given member.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ public sealed override Type GetInterface(string name, bool ignoreCase)
if (ns != null && !ns.Equals(ifc.Namespace))
continue;
if (match != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
match = ifc;
}
return match;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ protected sealed override PropertyInfo GetPropertyImpl(string name, BindingFlags
{
if (returnType is null)
// if we are here we have no args or property type to select over and we have more than one property with that name
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@
<data name="MissingMember" xml:space="preserve">
<value>Member not found.</value>
</data>
<data name="Arg_AmbiguousMatchException" xml:space="preserve">
<value>Ambiguous match found.</value>
</data>
<data name="Arg_HTCapacityOverflow" xml:space="preserve">
<value>Hashtable's capacity overflowed and went negative. Check load factor, capacity and the current size of the table.</value>
</data>
Expand Down Expand Up @@ -225,4 +222,4 @@
<data name="Acc_InitOnlyStatic" xml:space="preserve">
<value>Cannot set initonly static field after its owning type is initialized.</value>
</data>
</root>
</root>
12 changes: 6 additions & 6 deletions src/libraries/System.Private.CoreLib/src/System/DefaultBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public sealed override MethodBase BindToMethod(
}

if (ambig)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

// Reorder (if needed)
if (names != null)
Expand Down Expand Up @@ -515,7 +515,7 @@ public sealed override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo
}
}
if (ambig)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
return candidates[currentMin];
}

Expand Down Expand Up @@ -609,7 +609,7 @@ public sealed override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo
}
}
if (ambig)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
return candidates[currentMin];
}

Expand Down Expand Up @@ -725,7 +725,7 @@ public sealed override FieldInfo BindToField(BindingFlags bindingAttr, FieldInfo
}

if (ambig)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
return candidates[currentMin];
}

Expand Down Expand Up @@ -841,7 +841,7 @@ public sealed override void ReorderArgumentArray(ref object?[] args, object stat
continue;

if (bestMatch != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

bestMatch = match[i];
}
Expand Down Expand Up @@ -1128,7 +1128,7 @@ private static int GetHierarchyDepth(Type t)
// This can only happen if at least one is vararg or generic.
if (currentHierarchyDepth == deepestHierarchy)
{
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
}

// Check to see if this method is on the most derived class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,6 @@
<data name="Argument_InvalidEnum" xml:space="preserve">
<value>The enum type should contain one and only one instance field.</value>
</data>
<data name="Arg_AmbiguousMatchException" xml:space="preserve">
<value>Ambiguous match found.</value>
</data>
<data name="Arg_EmptyArray" xml:space="preserve">
<value>Array may not be empty.</value>
</data>
Expand Down Expand Up @@ -269,4 +266,4 @@
<data name="Arg_InvalidPath" xml:space="preserve">
<value>The path '{0}' is not valid.</value>
</data>
</root>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public sealed override MethodBase BindToMethod(
}
}
if (ambig)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
return candidates[currentMin];
}

Expand Down Expand Up @@ -257,7 +257,7 @@ public sealed override MethodBase BindToMethod(
}

if (ambig)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
return candidates[currentMin];
}

Expand Down Expand Up @@ -337,7 +337,7 @@ public sealed override MethodBase BindToMethod(
continue;

if (bestMatch != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

bestMatch = match[i];
}
Expand Down Expand Up @@ -602,7 +602,7 @@ private static int GetHierarchyDepth(Type t)
// This can only happen if at least one is vararg or generic.
if (currentHierarchyDepth == deepestHierarchy)
{
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
}

// Check to see if this method is on the most derived class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ internal abstract partial class RoType
{
if (returnType is null)
// if we are here we have no args or property type to select over and we have more than one property with that name
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ internal abstract partial class RoType
if (ns.Length != 0 && !ns.Equals(ifc.Namespace))
continue;
if (match != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
match = ifc;
}
return match;
Expand Down
14 changes: 7 additions & 7 deletions src/mono/System.Private.CoreLib/src/System/RuntimeType.Mono.cs
Original file line number Diff line number Diff line change
Expand Up @@ -797,7 +797,7 @@ public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
{
MethodInfo methodInfo = candidates[j];
if (!System.DefaultBinder.CompareMethodSig(methodInfo, firstCandidate))
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
}

// All the methods have the exact same name and sig so return the most derived one.
Expand Down Expand Up @@ -868,7 +868,7 @@ public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
{
if (returnType is null)
// if we are here we have no args or property type to select over and we have more than one property with that name
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();
}
}

Expand Down Expand Up @@ -900,7 +900,7 @@ public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
if ((bindingAttr & eventInfo.BindingFlags) == eventInfo.BindingFlags)
{
if (match != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

match = eventInfo;
}
Expand Down Expand Up @@ -929,7 +929,7 @@ public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
if (match != null)
{
if (ReferenceEquals(fieldInfo.DeclaringType, match.DeclaringType))
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

if ((match.DeclaringType!.IsInterface == true) && (fieldInfo.DeclaringType!.IsInterface == true))
multipleStaticFieldMatches = true;
Expand All @@ -941,7 +941,7 @@ public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
}

if (multipleStaticFieldMatches && match!.DeclaringType!.IsInterface)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

return match;
}
Expand Down Expand Up @@ -991,7 +991,7 @@ public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
if (FilterApplyType(iface, bindingAttr, name, false, ns))
{
if (match != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

match = iface;
}
Expand Down Expand Up @@ -1019,7 +1019,7 @@ public override MemberInfo[] GetMembers(BindingFlags bindingAttr)
if (FilterApplyType(nestedType, bindingAttr, name, false, ns))
{
if (match != null)
throw new AmbiguousMatchException(SR.Arg_AmbiguousMatchException);
throw new AmbiguousMatchException();

match = nestedType;
}
Expand Down

0 comments on commit 61250b4

Please sign in to comment.