Use explicit comparer for extension identifiers

pull/6938/head
Sydney Acksman 5 years ago
parent 145033c056
commit 34f9497162
  1. 13
      csharp/src/Google.Protobuf/ExtensionRegistry.cs
  2. 2
      csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs

@ -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)

Loading…
Cancel
Save