@@ -495,43 +495,24 @@ public static ITypeSymbol ConvertToType(
495495
496496 string WithArity ( string typeName , int arity ) => arity > 0 ? typeName + '`' + arity : typeName ;
497497
498- var delegateTypeName = method . ReturnsVoid
498+ // Convert the symbol to Func<...> or Action<...>
499+ var delegateType = compilation . GetTypeByMetadataName ( method . ReturnsVoid
499500 ? WithArity ( "System.Action" , count )
500- : WithArity ( "System.Func" , count + 1 ) ;
501- var delegateType = compilation . GetTypeByMetadataName ( delegateTypeName ) ;
501+ : WithArity ( "System.Func" , count + 1 ) ) ;
502502
503503 if ( delegateType != null )
504504 {
505- ITypeSymbol [ ] types ;
505+ var types = method . Parameters
506+ . Skip ( skip )
507+ . Select ( p => p . Type ?? compilation . GetSpecialType ( SpecialType . System_Object ) ) ;
506508
507- // Convert the symbol to Func<...> or Action<...>
508- if ( method . ReturnsVoid )
509+ if ( ! method . ReturnsVoid )
509510 {
510- // Action<TArg1, ..., TArgN>
511-
512- types = method . Parameters
513- . Skip ( skip )
514- . Select ( p =>
515- p . Type == null ?
516- compilation . GetSpecialType ( SpecialType . System_Object ) :
517- p . Type )
518- . ToArray ( ) ;
519- }
520- else
521- {
522- // Func<TArg1,...,TArgN,TReturn>
523- //
524511 // +1 for the return type.
525-
526- types = method . Parameters
527- . Skip ( skip )
528- . Select ( p => p . Type )
529- . Concat ( method . ReturnType )
530- . Select ( t => t ?? compilation . GetSpecialType ( SpecialType . System_Object ) )
531- . ToArray ( ) ;
512+ types = types . Concat ( method . ReturnType ?? compilation . GetSpecialType ( SpecialType . System_Object ) ) ;
532513 }
533514
534- return types . Length > 0 ? delegateType . Construct ( types ) : delegateType ;
515+ return delegateType . TryConstruct ( types . ToArray ( ) ) ;
535516 }
536517 }
537518
0 commit comments