private bool IsConvertibleTo([NotNull] IExpressionType expressionType, [NotNull] IType parameterType) { if (expressionType.IsImplicitlyConvertibleTo(parameterType, myConversionRule)) { return(true); } var declaredType = parameterType as IDeclaredType; if (declaredType != null) { var typeParameter = declaredType.GetTypeElement() as ITypeParameter; if (typeParameter != null) { var effectiveType = typeParameter.EffectiveBaseClass(); if (effectiveType != null && expressionType.IsImplicitlyConvertibleTo(effectiveType, myConversionRule)) { return(true); } } } var parameterArrayType = parameterType as IArrayType; if (parameterArrayType != null) { var expressionArrayType = expressionType as IArrayType; if (expressionArrayType != null && expressionArrayType.Rank == parameterArrayType.Rank) { if (IsConvertibleTo(expressionArrayType.ElementType, parameterArrayType.ElementType)) { return(true); } } } return(false); }
private IMethod FindAssertionMethod([NotNull] string assertionMethodName, [NotNull] IExpressionType parameterType, [NotNull] IPsiModule module) { var symbolScope = module.GetPsiServices().Symbols.GetSymbolScope(module, true, true); IClass typeDecl = null; if (this.CachedAssertClassTypeName != null) { typeDecl = symbolScope.GetTypeElementByCLRName(this.CachedAssertClassTypeName) as IClass; } else { var candidates = symbolScope.GetElementsByShortName(AssertTypeName).OfType <IClass>().Where(c => c.CanBeVisibleToSolution()).ToArray(); if (candidates.Length == 1) { typeDecl = candidates[0]; } if (typeDecl != null) { this.CachedAssertClassTypeName = typeDecl.GetClrName(); } } return(typeDecl? .EnumerateMembers(assertionMethodName, true) .OfType <IMethod>() .FirstOrDefault(m => m.Parameters.Count > 1 && (m.Parameters[0].Type.IsOpenType || parameterType.IsImplicitlyConvertibleTo(m.Parameters[0].Type, module.GetTypeConversionRule())))); }