当前位置: 首页>>代码示例>>C#>>正文


C# UnaryOperatorExpression类代码示例

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


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


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