From 3c2a32a75f15ba6a527ae267351de4160e1a1de7 Mon Sep 17 00:00:00 2001 From: Sydney Acksman Date: Sun, 24 Nov 2019 14:22:26 -0600 Subject: [PATCH] Use Distinct on depended extensions to filter duplicate extensions --- csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs index 388a40b4bb..37afdcc657 100644 --- a/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs +++ b/csharp/src/Google.Protobuf/Reflection/FileDescriptor.cs @@ -422,7 +422,8 @@ namespace Google.Protobuf.Reflection GeneratedClrTypeInfo generatedCodeInfo) { ExtensionRegistry registry = new ExtensionRegistry(); - AddAllExtensions(dependencies, generatedCodeInfo, registry); + registry.AddRange(GetAllExtensions(dependencies, generatedCodeInfo)); + FileDescriptorProto proto; try { @@ -445,9 +446,9 @@ namespace Google.Protobuf.Reflection } } - private static void AddAllExtensions(FileDescriptor[] dependencies, GeneratedClrTypeInfo generatedInfo, ExtensionRegistry registry) + private static IEnumerable GetAllExtensions(FileDescriptor[] dependencies, GeneratedClrTypeInfo generatedInfo) { - registry.AddRange(dependencies.SelectMany(GetAllDependedExtensions).Concat(GetAllGeneratedExtensions(generatedInfo)).ToArray()); + return dependencies.SelectMany(GetAllDependedExtensions).Distinct().Concat(GetAllGeneratedExtensions(generatedInfo)); } private static IEnumerable GetAllGeneratedExtensions(GeneratedClrTypeInfo generated)