public IPhpValue TranslateToPhp(IExternalTranslationContext ctx, CsharpInstancePropertyAccessExpression src) { if (src.Member.DeclaringType == typeof(MySQLi)) { var n = src.Member.Name; if (n == "WasConnectionError" || n == "WasSuccessfulConnection") { // according to error http://www.php.net/manual/en/mysqli.construct.php IPhpValue getError; if (ctx.PhpVersion <= PhpVersions.PHP_5_3_0) { getError = new PhpMethodCallExpression("mysqli_connect_error"); } else { getError = new PhpInstanceFieldAccessExpression("connect_error", ctx.TranslateValue(src.TargetObject), null); } var checkEmpty = new PhpMethodCallExpression("empty", getError); if (n == "WasSuccessfulConnection") { return(checkEmpty); } var checkNotEmpty = new PhpUnaryOperatorExpression(checkEmpty, "!"); return(checkNotEmpty); } } return(null); }
protected override IPhpValue VisitUnaryOperatorExpression(UnaryOperatorExpression src) { var v = TransValue(src.Operand); var a = new PhpUnaryOperatorExpression(v, src.Operator); return(SimplifyPhpExpression(a)); }
protected virtual T VisitPhpUnaryOperatorExpression(PhpUnaryOperatorExpression node) { if (ThrowNotImplementedException) { throw new NotImplementedException(string.Format("Method {0} is not supported in class {1}", "VisitPhpUnaryOperatorExpression", this.GetType().FullName)); } return(default(T)); }
private IPhpValue _Nullable() { var s = src.Member.Name; if (s == "Value") { var targetObject = ctx.TranslateValue(src.TargetObject); return(targetObject); } if (s == "HasValue") { var targetObject = ctx.TranslateValue(src.TargetObject); var _isNull = new PhpMethodCallExpression("is_null", targetObject); var _notNull = new PhpUnaryOperatorExpression(_isNull, "!"); return(_notNull); } throw new NotSupportedException(); }
private IPhpValue _Nullable() { var s = _src.Member.Name; switch (s) { case "Value": { var targetObject = _ctx.TranslateValue(_src.TargetObject); return(targetObject); } case "HasValue": { var targetObject = _ctx.TranslateValue(_src.TargetObject); var isNull = new PhpMethodCallExpression("is_null", targetObject); var notNull = new PhpUnaryOperatorExpression(isNull, "!"); return(notNull); } } throw new NotSupportedException(); }
protected override IPhpValue VisitPhpUnaryOperatorExpression(PhpUnaryOperatorExpression node) { if (node.Operator == "!" && node.Operand is PhpBinaryOperatorExpression) { var bin = node.Operand as PhpBinaryOperatorExpression; if (bin.Operator == "!==") { var bin2 = new PhpBinaryOperatorExpression("===", bin.Left, bin.Right); return(bin2); } var be = new PhpParenthesizedExpression(node.Operand); node = new PhpUnaryOperatorExpression(be, node.Operator); return(node); } if (node.Operator == "!" && node.Operand is PhpUnaryOperatorExpression) { var bin = node.Operand as PhpUnaryOperatorExpression; if (bin.Operator == "!") { return(Simplify(bin.Operand)); } } return(node); }