Commit 34f94971 authored by Sydney Acksman's avatar Sydney Acksman

Use explicit comparer for extension identifiers

parent 145033c0
......@@ -42,6 +42,19 @@ namespace Google.Protobuf
/// </summary>
public sealed class ExtensionRegistry : ICollection<Extension>, IDeepCloneable<ExtensionRegistry>
{
internal sealed class ExtensionComparer : IEqualityComparer<Extension>
{
public bool Equals(Extension a, Extension b)
{
return new ObjectIntPair<Type>(a.TargetType, a.FieldNumber).Equals(new ObjectIntPair<Type>(b.TargetType, b.FieldNumber));
}
public int GetHashCode(Extension a)
{
return new ObjectIntPair<Type>(a.TargetType, a.FieldNumber).GetHashCode();
}
internal static ExtensionComparer Instance = new ExtensionComparer();
}
private IDictionary<ObjectIntPair<Type>, Extension> extensions;
/// <summary>
......
......@@ -448,7 +448,7 @@ namespace Google.Protobuf.Reflection
private static IEnumerable<Extension> GetAllExtensions(FileDescriptor[] dependencies, GeneratedClrTypeInfo generatedInfo)
{
return dependencies.SelectMany(GetAllDependedExtensions).Distinct().Concat(GetAllGeneratedExtensions(generatedInfo));
return dependencies.SelectMany(GetAllDependedExtensions).Distinct(ExtensionRegistry.ExtensionComparer.Instance).Concat(GetAllGeneratedExtensions(generatedInfo));
}
private static IEnumerable<Extension> GetAllGeneratedExtensions(GeneratedClrTypeInfo generated)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment