• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UnaryOperatorExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UnaryOperatorExpression的典型用法代码示例。如果您正苦于以下问题:C# UnaryOperatorExpression类的具体用法?C# UnaryOperatorExpression怎么用?C# UnaryOperatorExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UnaryOperatorExpression类属于命名空间,在下文中一共展示了UnaryOperatorExpression类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: VisitUnaryOperatorExpression

			public override void VisitUnaryOperatorExpression (UnaryOperatorExpression unaryOperatorExpression)
			{
				base.VisitUnaryOperatorExpression (unaryOperatorExpression);

				if (unaryOperatorExpression.Operator != UnaryOperatorType.Not)
					return;

				var expr = unaryOperatorExpression.Expression;
				while (expr != null && expr is ParenthesizedExpression)
					expr = ((ParenthesizedExpression)expr).Expression;

				var binaryOperatorExpr = expr as BinaryOperatorExpression;
				if (binaryOperatorExpr == null)
					return;

				var negatedOp = CSharpUtil.NegateRelationalOperator(binaryOperatorExpr.Operator);
				if (negatedOp == BinaryOperatorType.Any)
					return;

				if (IsFloatingPoint (binaryOperatorExpr.Left) || IsFloatingPoint (binaryOperatorExpr.Right)) {
					if (negatedOp != BinaryOperatorType.Equality && negatedOp != BinaryOperatorType.InEquality)
						return;
				}

				AddIssue (unaryOperatorExpression, ctx.TranslateString ("Simplify negative relational expression"),
					script => script.Replace (unaryOperatorExpression,
						new BinaryOperatorExpression (binaryOperatorExpr.Left.Clone (), negatedOp,
					          	binaryOperatorExpr.Right.Clone ())));
			}
开发者ID:RainsSoft,项目名称:playscript-monodevelop,代码行数:29,代码来源:NegativeRelationalExpressionIssue.cs


示例2: VisitUnaryOperatorExpression

		public override object VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, object data)
		{
			if (unaryOperatorExpression.Op == UnaryOperatorType.Not) {
				return unaryOperatorExpression.Expression.AcceptVisitor(this, data) == SymbolDefined ? null : SymbolDefined;
			} else {
				return null;
			}
		}
开发者ID:mgagne-atman,项目名称:Projects,代码行数:8,代码来源:ConditionalCompilation.cs


示例3: TrickyCast3

		public void TrickyCast3()
		{
			Expression expr = new UnaryOperatorExpression(
				UnaryOperatorType.Not, new IdentifierExpression("a")
			).CastTo(new SimpleType("MyType"));
			
			Assert.AreEqual("(MyType)!a", InsertRequired(expr));
			Assert.AreEqual("(MyType)(!a)", InsertReadable(expr));
		}
开发者ID:qjlee,项目名称:ILSpy,代码行数:9,代码来源:InsertParenthesesVisitorTests.cs


示例4: TrickyCast1

		public void TrickyCast1()
		{
			Expression expr = new UnaryOperatorExpression(
				UnaryOperatorType.Minus, new IdentifierExpression("a")
			).CastTo(new PrimitiveType("int"));
			
			Assert.AreEqual("(int)-a", InsertRequired(expr));
			Assert.AreEqual("(int)(-a)", InsertReadable(expr));
		}
开发者ID:qjlee,项目名称:ILSpy,代码行数:9,代码来源:InsertParenthesesVisitorTests.cs


示例5: DoubleNegation

        public void DoubleNegation()
        {
            Expression expr = new UnaryOperatorExpression(
                UnaryOperatorType.Minus,
                new UnaryOperatorExpression(UnaryOperatorType.Minus, new IdentifierExpression("a"))
            );

            Assert.AreEqual("- -a", InsertRequired(expr));
            Assert.AreEqual("-(-a)", InsertReadable(expr));
        }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:10,代码来源:InsertParenthesesVisitorTests.cs


示例6: VisitUnaryOperatorExpression

 public override void VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression)
 {
     if (unaryOperatorExpression.Operator == UnaryOperatorType.Await) {
         _errorReporter.Message(7998, unaryOperatorExpression.GetRegion(), "await");
         _result = false;
     }
     else {
         base.VisitUnaryOperatorExpression(unaryOperatorExpression);
     }
 }
开发者ID:arnauddias,项目名称:SaltarelleCompiler,代码行数:10,代码来源:UnsupportedConstructsScanner.cs


示例7: GetControlVariable

			static VariableInitializer GetControlVariable(VariableDeclarationStatement variableDecl,
														  UnaryOperatorExpression condition)
			{
				var controlVariables = variableDecl.Variables.Where (
					v =>
					{
						var identifier = new IdentifierExpression (v.Name);
						return condition.Expression.Match (identifier).Success;
					}).ToList ();
				return controlVariables.Count == 1 ? controlVariables [0] : null;
			}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:11,代码来源:ForControlVariableNotModifiedIssue.cs


示例8: VisitUnaryOperatorExpression

        public override void VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression)
        {
            if (unaryOperatorExpression.Operator == UnaryOperatorType.Await)
            {
                var tryBlock = unaryOperatorExpression.GetParent<TryCatchStatement>();

                if (tryBlock != null)
                {
                    this.Found = true;
                }
            }

            base.VisitUnaryOperatorExpression(unaryOperatorExpression);
        }
开发者ID:txdv,项目名称:Builder,代码行数:14,代码来源:AwaitSearchVisitor.cs


示例9: GetValueFromUnaryExpression

        public static dynamic GetValueFromUnaryExpression(UnaryOperatorExpression expr)
        {
            var value = GetValueFromExpression(expr.Expression);
            if (value == null)
                return null;

            switch (expr.Operator)
            {
                case UnaryOperatorType.Not:
                    return !value;
                case UnaryOperatorType.Minus:
                    return -value;
                case UnaryOperatorType.Plus:
                    return +value;
                default:
                    return null;
            }
        }
开发者ID:TreeSeed,项目名称:Tychaia,代码行数:18,代码来源:AstHelpers.cs


示例10: VisitUnaryOperatorExpression

			public override void VisitUnaryOperatorExpression (UnaryOperatorExpression unaryOperatorExpression)
			{
				base.VisitUnaryOperatorExpression (unaryOperatorExpression);

				if (unaryOperatorExpression.Operator != UnaryOperatorType.Not)
					return;

				var innerUnaryOperatorExpr = 
					RemoveParentheses (unaryOperatorExpression.Expression) as UnaryOperatorExpression;
				if (innerUnaryOperatorExpr == null || innerUnaryOperatorExpr.Operator != UnaryOperatorType.Not)
					return;

				var expression = RemoveParentheses (innerUnaryOperatorExpr.Expression);
				if (expression.IsNull)
					return;

				AddIssue (unaryOperatorExpression, ctx.TranslateString ("Remove double negation"),
					script => script.Replace (unaryOperatorExpression, expression.Clone ()));
			}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:19,代码来源:DoubleNegationIssue.cs


示例11: GetActions

		public override IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			var node = context.GetNode<BinaryOperatorExpression>();
			if (node == null || 
			    (node.Operator != BinaryOperatorType.Equality && node.Operator != BinaryOperatorType.InEquality) ||
			    !node.OperatorToken.Contains(context.Location))
				yield break;

			yield return new CodeAction(
				context.TranslateString("Use 'Equals'"),
				script => {
					Expression expr = new InvocationExpression(GenerateTarget(context, node), node.Left.Clone(), node.Right.Clone());
					if (node.Operator == BinaryOperatorType.InEquality)
						expr = new UnaryOperatorExpression(UnaryOperatorType.Not, expr);
					script.Replace(node, expr);
				}, 
				node.OperatorToken
			);
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:19,代码来源:ConvertEqualityOperatorToEqualsAction.cs


示例12: VisitBinaryOperatorExpression

			public override void VisitBinaryOperatorExpression (BinaryOperatorExpression binaryOperatorExpression)
			{
				base.VisitBinaryOperatorExpression (binaryOperatorExpression);

				var match = pattern.Match (binaryOperatorExpression);
				if (!match.Success)
					return;

				AddIssue (binaryOperatorExpression, ctx.TranslateString ("Simplify boolean comparison"), scrpit => {
					var expr = match.Get<Expression> ("expr").First ().Clone ();
					var boolConstant = (bool)match.Get<PrimitiveExpression> ("const").First ().Value;
					if ((binaryOperatorExpression.Operator == BinaryOperatorType.InEquality && boolConstant) ||
						(binaryOperatorExpression.Operator == BinaryOperatorType.Equality && !boolConstant)) {
						expr = new UnaryOperatorExpression (UnaryOperatorType.Not, expr);
						expr.AcceptVisitor (insertParenthesesVisitor);
					}
					scrpit.Replace (binaryOperatorExpression, expr);
				});
			}
开发者ID:mono-soc-2012,项目名称:NRefactory,代码行数:19,代码来源:CompareBooleanWithTrueOrFalseIssue.cs


示例13: ResolveOperator

        protected bool ResolveOperator(UnaryOperatorExpression unaryOperatorExpression, OperatorResolveResult orr)
        {
            if (orr != null && orr.UserDefinedOperatorMethod != null)
            {
                var method = orr.UserDefinedOperatorMethod;
                var inline = this.Emitter.GetInline(method);

                if (!string.IsNullOrWhiteSpace(inline))
                {
                    new InlineArgumentsBlock(this.Emitter, new ArgumentsInfo(this.Emitter, unaryOperatorExpression, orr, method), inline).Emit();
                    return true;
                }
                else
                {
                    if (orr.IsLiftedOperator)
                    {
                        this.Write(Bridge.Translator.Emitter.ROOT + ".Nullable.lift(");
                    }

                    this.Write(BridgeTypes.ToJsName(method.DeclaringType, this.Emitter));
                    this.WriteDot();

                    this.Write(OverloadsCollection.Create(this.Emitter, method).GetOverloadName());

                    if (orr.IsLiftedOperator)
                    {
                        this.WriteComma();
                    }
                    else
                    {
                        this.WriteOpenParentheses();
                    }

                    new ExpressionListBlock(this.Emitter, new Expression[] { unaryOperatorExpression.Expression }, null).Emit();
                    this.WriteCloseParentheses();

                    return true;
                }
            }

            return false;
        }
开发者ID:RashmiPankaj,项目名称:Bridge,代码行数:42,代码来源:UnaryOperatorBlock.cs


示例14: GetActions

		public override System.Collections.Generic.IEnumerable<CodeAction> GetActions(RefactoringContext context)
		{
			Expression expr = null;
			AstNode token;
			if (!NegateRelationalExpressionAction.GetLogicalExpression (context, out expr, out token))
				yield break;

			var uOp = expr as UnaryOperatorExpression;
			if (uOp != null) {
				yield return new CodeAction(
					string.Format(context.TranslateString("Invert '{0}'"), expr),
					script => {
						script.Replace(uOp, CSharpUtil.InvertCondition(CSharpUtil.GetInnerMostExpression(uOp.Expression)));
					}, token
				);	
				yield break;
			}

			var negativeExpression = CSharpUtil.InvertCondition(expr);
			if (expr.Parent is ParenthesizedExpression && expr.Parent.Parent is UnaryOperatorExpression) {
				var unaryOperatorExpression = expr.Parent.Parent as UnaryOperatorExpression;
				if (unaryOperatorExpression.Operator == UnaryOperatorType.Not) {
					yield return new CodeAction(
						string.Format(context.TranslateString("Invert '{0}'"), unaryOperatorExpression),
						script => {
							script.Replace(unaryOperatorExpression, negativeExpression);
						}, token
					);	
					yield break;
				}
			}
			var newExpression = new UnaryOperatorExpression(UnaryOperatorType.Not, new ParenthesizedExpression(negativeExpression));
			yield return new CodeAction(
				string.Format(context.TranslateString("Invert '{0}'"), expr),
				script => {
					script.Replace(expr, newExpression);
				}, token
			);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:39,代码来源:InvertLogicalExpressionAction.cs


示例15: VisitBinaryOperatorExpression

			public override void VisitBinaryOperatorExpression (BinaryOperatorExpression binaryOperatorExpression)
			{
				base.VisitBinaryOperatorExpression (binaryOperatorExpression);

				var match = pattern.Match (binaryOperatorExpression);
				if (!match.Success)
					return;
				var expr = match.First<Expression>("expr");
				// check if expr is of boolean type
				var exprType = ctx.Resolve (expr).Type.GetDefinition ();
				if (exprType == null || exprType.KnownTypeCode != KnownTypeCode.Boolean)
					return;

				AddIssue (binaryOperatorExpression, ctx.TranslateString ("Simplify boolean comparison"), scrpit => {
                    var boolConstant = (bool)match.First<PrimitiveExpression>("const").Value;
					if ((binaryOperatorExpression.Operator == BinaryOperatorType.InEquality && boolConstant) ||
						(binaryOperatorExpression.Operator == BinaryOperatorType.Equality && !boolConstant)) {
						expr = new UnaryOperatorExpression (UnaryOperatorType.Not, expr.Clone());
						expr.AcceptVisitor (insertParenthesesVisitor);
					}
					scrpit.Replace (binaryOperatorExpression, expr);
				});
			}
开发者ID:x-strong,项目名称:ILSpy,代码行数:23,代码来源:CompareBooleanWithTrueOrFalseIssue.cs


示例16: ExtractExpression

		bool ExtractExpression (Statement statement, out Expression leftSide, out Expression rightSide) {
			ExpressionStatement expression = statement as ExpressionStatement;
			if (expression != null) {
				AssignmentExpression assignment = expression.Expression as AssignmentExpression;
				if (assignment != null) {
					if (assignment.Operator == AssignmentOperatorType.Add) {
						leftSide = assignment.Left;
						rightSide = assignment.Right;
						return true;
					}
					if (assignment.Operator == AssignmentOperatorType.Subtract) {
						leftSide = assignment.Left;
						rightSide = new UnaryOperatorExpression(UnaryOperatorType.Minus, assignment.Right.Clone());
						return true;
					}

					leftSide = null;
					rightSide = null;
					return false;
				}

				UnaryOperatorExpression unary = expression.Expression as UnaryOperatorExpression;
				if (unary != null) {
					leftSide = unary.Expression;
					if (unary.Operator == UnaryOperatorType.Increment || unary.Operator == UnaryOperatorType.PostIncrement) {
						rightSide = new PrimitiveExpression(1);
						return true;
					} else if (unary.Operator == UnaryOperatorType.Decrement || unary.Operator == UnaryOperatorType.PostDecrement) {
						rightSide = new PrimitiveExpression(-1);
						return true;
					} else {
						leftSide = null;
						rightSide = null;
						return false;
					}
				}
			}

			if (statement is EmptyStatement || statement.IsNull) {
				leftSide = null;
				rightSide = null;
				return true;
			}

			BlockStatement block = statement as BlockStatement;
			if (block != null) {
				leftSide = null;
				rightSide = null;

				foreach (Statement child in block.Statements) {
					Expression newLeft, newRight;
					if (!ExtractExpression(child, out newLeft, out newRight)) {
						leftSide = null;
						rightSide = null;
						return false;
					}

					if (newLeft == null) {
						continue;
					}

					if (leftSide == null) {
						leftSide = newLeft;
						rightSide = newRight;
					} else if (SameNode(leftSide, newLeft)) {
						rightSide = new BinaryOperatorExpression(ParenthesizeIfNeeded(rightSide).Clone(),
						                                         BinaryOperatorType.Add,
						                                         ParenthesizeIfNeeded(newRight).Clone());
					} else {
						return false;
					}
				}

				return true;
			}

			IfElseStatement condition = statement as IfElseStatement;
			if (condition != null) {
				Expression ifLeft, ifRight;
				if (!ExtractExpression(condition.TrueStatement, out ifLeft, out ifRight)) {
					leftSide = null;
					rightSide = null;
					return false;
				}

				Expression elseLeft, elseRight;
				if (!ExtractExpression(condition.FalseStatement, out elseLeft, out elseRight)) {
					leftSide = null;
					rightSide = null;
					return false;
				}

				if (ifLeft == null && elseLeft == null) {
					leftSide = null;
					rightSide = null;
					return true;
				}

				if (ifLeft != null && elseLeft != null && !SameNode(ifLeft, elseLeft)) {
					leftSide = null;
//.........这里部分代码省略.........
开发者ID:qhta,项目名称:NRefactory,代码行数:101,代码来源:AutoLinqSumAction.cs


示例17: IsUnaryModifierExpression

		bool IsUnaryModifierExpression(UnaryOperatorExpression expr)
		{
			return expr.Operator == UnaryOperatorType.Increment || expr.Operator == UnaryOperatorType.PostIncrement || expr.Operator == UnaryOperatorType.Decrement || expr.Operator == UnaryOperatorType.PostDecrement;
		}
开发者ID:qhta,项目名称:NRefactory,代码行数:4,代码来源:AutoLinqSumAction.cs


示例18: VisitUnaryOperatorExpression

		public void VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression)
		{
			StartNode(unaryOperatorExpression);
			UnaryOperatorType opType = unaryOperatorExpression.Operator;
			var opSymbol = UnaryOperatorExpression.GetOperatorRole(opType);
			if (opType == UnaryOperatorType.Await) {
				WriteKeyword(opSymbol);
			} else if (!(opType == UnaryOperatorType.PostIncrement || opType == UnaryOperatorType.PostDecrement)) {
				WriteToken(opSymbol);
			}
			unaryOperatorExpression.Expression.AcceptVisitor(this);
			if (opType == UnaryOperatorType.PostIncrement || opType == UnaryOperatorType.PostDecrement) {
				WriteToken(opSymbol);
			}
			EndNode(unaryOperatorExpression);
		}
开发者ID:x-strong,项目名称:ILSpy,代码行数:16,代码来源:CSharpOutputVisitor.cs


示例19: Visit

			public override object Visit (Indirection indirectionExpression)
			{
				var result = new UnaryOperatorExpression ();
				result.UnaryOperatorType = UnaryOperatorType.Dereference;
				var location = LocationsBag.GetLocations (indirectionExpression);
				if (location != null)
					result.AddChild (new CSharpTokenNode (Convert (location[0]), 2), UnaryOperatorExpression.Operator);
				result.AddChild ((INode)indirectionExpression.Expr.Accept (this), UnaryOperatorExpression.Roles.Expression);
				return result;
			}
开发者ID:pgoron,项目名称:monodevelop,代码行数:10,代码来源:CSharpParser.cs


示例20: VisitUnaryOperatorExpression

        public override StringBuilder VisitUnaryOperatorExpression(UnaryOperatorExpression unaryOperatorExpression, int data)
        {
            var result = new StringBuilder();

            var exp = unaryOperatorExpression.Expression.AcceptVisitor(this, data);

            switch (unaryOperatorExpression.Operator)
            {
                case UnaryOperatorType.Decrement:
                    return result.Append("--").Append(exp);
                case UnaryOperatorType.Increment:
                    return result.Append("++").Append(exp);
                case UnaryOperatorType.Minus:
                    return result.Append("-").Append(exp);
                case UnaryOperatorType.Plus:
                    return result.Append("+").Append(exp);
                case UnaryOperatorType.BitNot:
                    return result.Append("~").Append(exp);
                case UnaryOperatorType.Not:
                    return result.Append("!").Append(exp);
                case UnaryOperatorType.PostDecrement:
                    return result.Append(exp).Append("--");
                case UnaryOperatorType.PostIncrement:
                    return result.Append(exp).Append("++");
            }

            throw new NotImplementedException();
        }
开发者ID:mono-soc-2011,项目名称:SLSharp,代码行数:28,代码来源:GlslVisitor.cs



注:本文中的UnaryOperatorExpression类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UnaryOperatorKind类代码示例发布时间:2022-05-24
下一篇:
C# UnaryOperator类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap