public override Conversion ClassifyConversion(LanguageSyntaxNode expression, ITypeSymbol destination, bool isExplicitInSource = false) { var csdestination = destination.EnsureLanguageSymbolOrNull <ITypeSymbol, TypeSymbol>(nameof(destination)); if (isExplicitInSource) { return(ClassifyConversionForCast(expression, csdestination)); } CheckSyntaxNode(expression); if ((object)destination == null) { throw new ArgumentNullException(nameof(destination)); } // TODO(cyrusn): Check arguments. This is a public entrypoint, so we must do appropriate // checks here. However, no other methods in this type do any checking currently. So I'm // going to hold off on this until we do a full sweep of the API. var model = this.GetMemberModel(expression); if (model == null) { // 'expression' must just be reference to a type or namespace name outside of an // expression context. Currently we bail in that case. However, is this a question // that a client would be asking and would expect sensible results for? return(Conversion.NoConversion); } return(model.ClassifyConversion(expression, destination)); }
public override Conversion ClassifyConversion( LanguageSyntaxNode expression, ITypeSymbol destination, bool isExplicitInSource = false) { if ((object)destination == null) { throw new ArgumentNullException(nameof(destination)); } var csdestination = destination.EnsureLanguageSymbolOrNull <ITypeSymbol, TypeSymbol>(nameof(destination)); if (isExplicitInSource) { return(ClassifyConversionForCast(expression, csdestination)); } // Note that it is possible for an expression to be convertible to a type // via both an implicit user-defined conversion and an explicit built-in conversion. // In that case, this method chooses the implicit conversion. CheckSyntaxNode(expression); var binder = this.GetEnclosingBinderInternal(expression, GetAdjustedNodePosition(expression)); LanguageSyntaxNode bindableNode = this.GetBindableSyntaxNode(expression); var boundExpression = this.GetLowerBoundNode(bindableNode) as BoundExpression; if (binder == null || boundExpression == null) { return(Conversion.NoConversion); } HashSet <DiagnosticInfo> useSiteDiagnostics = null; return(binder.Conversions.ClassifyConversionFromExpression(boundExpression, csdestination, ref useSiteDiagnostics)); }