/// <summary> /// Return the extension method in reduced form if the extension method /// is applicable, and satisfies type parameter constraints, based on the /// "this" argument type. Otherwise, returns null. /// </summary> public static MethodSymbol Create(MethodSymbol method, TypeSymbol receiverType, Compilation compilation) { Debug.Assert(method.IsExtensionMethod && method.MethodKind != MethodKind.ReducedExtension); Debug.Assert(method.ParameterCount > 0); Debug.Assert((object)receiverType != null); HashSet <DiagnosticInfo> useSiteDiagnostics = null; method = method.InferExtensionMethodTypeArguments(receiverType, compilation, ref useSiteDiagnostics); if ((object)method == null) { return(null); } var conversions = new TypeConversions(method.ContainingAssembly.CorLibrary); var conversion = conversions.ConvertExtensionMethodThisArg(method.Parameters[0].Type, receiverType, ref useSiteDiagnostics); if (!conversion.Exists) { return(null); } if (useSiteDiagnostics != null) { foreach (var diag in useSiteDiagnostics) { if (diag.Severity == DiagnosticSeverity.Error) { return(null); } } } return(Create(method)); }
/// <summary> /// Return the extension method in reduced form if the extension method /// is applicable, and satisfies type parameter constraints, based on the /// "this" argument type. Otherwise, returns null. /// </summary> public static MethodSymbol Create(MethodSymbol method, TypeSymbol receiverType, Compilation compilation) { Debug.Assert(method.IsExtensionMethod && method.MethodKind != MethodKind.ReducedExtension); Debug.Assert(method.ParameterCount > 0); Debug.Assert((object)receiverType != null); HashSet<DiagnosticInfo> useSiteDiagnostics = null; method = method.InferExtensionMethodTypeArguments(receiverType, compilation, ref useSiteDiagnostics); if ((object)method == null) { return null; } var conversions = new TypeConversions(method.ContainingAssembly.CorLibrary); var conversion = conversions.ConvertExtensionMethodThisArg(method.Parameters[0].Type, receiverType, ref useSiteDiagnostics); if (!conversion.Exists) { return null; } if (useSiteDiagnostics != null) { foreach (var diag in useSiteDiagnostics) { if (diag.Severity == DiagnosticSeverity.Error) { return null; } } } return Create(method); }