Ejemplo n.º 1
0
 void VisitTypeCastExpression(Expression expression, IType exprType, IType castToType)
 {
     if (TypeCompatibilityHelper.CheckTypeCompatibility(exprType, castToType) ==
         TypeCompatibilityHelper.TypeCompatiblity.NeverOfProvidedType)
     {
         AddIssue(expression, ctx.TranslateString("Type cast expression of incompatible type"));
     }
 }
Ejemplo n.º 2
0
            public override void VisitIsExpression(IsExpression isExpression)
            {
                base.VisitIsExpression(isExpression);

                var exprType     = ctx.Resolve(isExpression.Expression).Type;
                var providedType = ctx.ResolveType(isExpression.Type);

                if (TypeCompatibilityHelper.CheckTypeCompatibility(exprType, providedType) ==
                    TypeCompatibilityHelper.TypeCompatiblity.NeverOfProvidedType)
                {
                    AddIssue(isExpression, ctx.TranslateString("Given expression is never of the provided type"));
                }
            }
Ejemplo n.º 3
0
            public override void VisitIsExpression(IsExpression isExpression)
            {
                base.VisitIsExpression(isExpression);

                var type         = ctx.Resolve(isExpression.Expression).Type;
                var providedType = ctx.ResolveType(isExpression.Type);

                if (TypeCompatibilityHelper.CheckTypeCompatibility(type, providedType) !=
                    TypeCompatibilityHelper.TypeCompatiblity.AlwaysOfProvidedType)
                {
                    return;
                }

                var action = new CodeAction(ctx.TranslateString("Compare with 'null'"),
                                            scrpit => scrpit.Replace(isExpression, new BinaryOperatorExpression(
                                                                         isExpression.Expression.Clone(), BinaryOperatorType.InEquality, new PrimitiveExpression(null))));

                AddIssue(isExpression, ctx.TranslateString("Given expression is always of the provided type. " +
                                                           "Consider comparing with 'null' instead"), new [] { action });
            }