diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/INamedTypeSymbolExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/INamedTypeSymbolExtensions.cs index 4a8133716e551..c10555a3ff89b 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/INamedTypeSymbolExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/INamedTypeSymbolExtensions.cs @@ -531,5 +531,8 @@ private static void RemoveOverriddenMembers( } } } + + public static INamedTypeSymbol TryConstruct(this INamedTypeSymbol type, ITypeSymbol[] typeArguments) + => typeArguments.Length > 0 ? type.Construct(typeArguments) : type; } } diff --git a/src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs b/src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs index 0f6727fd3b335..18898f1d79ea6 100644 --- a/src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs +++ b/src/Workspaces/Core/Portable/Shared/Extensions/ISymbolExtensions.cs @@ -495,43 +495,24 @@ public static ITypeSymbol ConvertToType( string WithArity(string typeName, int arity) => arity > 0 ? typeName + '`' + arity : typeName; - var delegateTypeName = method.ReturnsVoid + // Convert the symbol to Func<...> or Action<...> + var delegateType = compilation.GetTypeByMetadataName(method.ReturnsVoid ? WithArity("System.Action", count) - : WithArity("System.Func", count + 1); - var delegateType = compilation.GetTypeByMetadataName(delegateTypeName); + : WithArity("System.Func", count + 1)); if (delegateType != null) { - ITypeSymbol[] types; + var types = method.Parameters + .Skip(skip) + .Select(p => p.Type ?? compilation.GetSpecialType(SpecialType.System_Object)); - // Convert the symbol to Func<...> or Action<...> - if (method.ReturnsVoid) + if (!method.ReturnsVoid) { - // Action - - types = method.Parameters - .Skip(skip) - .Select(p => - p.Type == null ? - compilation.GetSpecialType(SpecialType.System_Object) : - p.Type) - .ToArray(); - } - else - { - // Func - // // +1 for the return type. - - types = method.Parameters - .Skip(skip) - .Select(p => p.Type) - .Concat(method.ReturnType) - .Select(t => t ?? compilation.GetSpecialType(SpecialType.System_Object)) - .ToArray(); + types = types.Concat(method.ReturnType ?? compilation.GetSpecialType(SpecialType.System_Object)); } - return types.Length > 0 ? delegateType.Construct(types) : delegateType; + return delegateType.TryConstruct(types.ToArray()); } }