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


C# ExpressionResult类代码示例

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


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

示例1: ShouldWriteSummary

        public void ShouldWriteSummary()
        {
            var example = new ExampleResult {
                Reason = Resources.TestReason,
                ElapsedTime = 1000,
                Message = "Test Exception",
                StackTrace = "System.InvalidOperationException: Test Exception",
                Status = ResultStatus.Error
            };
            var results = new Collection<ExpressionResult>();
            var expression = new ExpressionResult();
            var group = new ExampleGroupResult();
            group.Examples.Add(example);
            expression.Examples.Add(group);
            results.Add(expression);

            this.consoleFormatter.WriteError(example);
            this.consoleFormatter.WriteSummary(results);
            this.stringWriter.Flush();

            var value = "F" + Environment.NewLine + Environment.NewLine +
                "Failures:" + Environment.NewLine + Environment.NewLine +
                "1) test" + Environment.NewLine +
                "   Failure/Error: System.InvalidOperationException: Test Exception" + Environment.NewLine + Environment.NewLine + 
                "Finished in 1 seconds" + Environment.NewLine + 
                "1 examples, 1 failures" + Environment.NewLine;
            this.stringWriter.ToString().Should().Be(value);
        }
开发者ID:alexfalkowski,项目名称:System.Spec,代码行数:28,代码来源:ProgressConsoleFormatterSpecs.cs

示例2: TestGetResultAsBoolean

        public void TestGetResultAsBoolean(object value, bool expectedValue)
        {
            // Arrange
              var sut = new ExpressionResult(value);

              // Act
              var result = sut.GetValueAsBoolean();

              // Assert
              Assert.AreEqual(expectedValue, result);
        }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:11,代码来源:TestExpressionResult.cs

示例3: Evaluate

        /// <summary>
        /// Evaluate the specified expression and return the result.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This implementation is hard-coded to return an <see cref="ExpressionResult"/> which indicates an evaluation
        /// failure.
        /// </para>
        /// </remarks>
        /// <param name="expression">The expression to evaluate.</param>
        /// <param name="element">The element for which we are evaluating a result.</param>
        public override ExpressionResult Evaluate(string expression, IRenderingContext context)
        {
            object result;
              ExpressionResult output;

              if(this.TryGetItem(expression, context, out result))
              {
            output = new ExpressionResult(result);
              }
              else
              {
            string message = String.Format("The item '{0}' was not found in the model.",
                                       expression);
            throw new InvalidOperationException(message);
              }

              return output;
        }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:29,代码来源:DummyModel.cs

示例4: CoerceToBoolean

        /// <summary>
        /// Coerces an expression result to a boolean value.
        /// </summary>
        /// <returns><c>true</c>, if the expression result indicates truth, <c>false</c> otherwise.</returns>
        /// <param name="result">An expression result.</param>
        private bool CoerceToBoolean(ExpressionResult result)
        {
            if(result == null)
              {
            throw new ArgumentNullException(nameof(result));
              }

              bool output;

              if(result.CancelsAction)
              {
            output = false;
              }
              else if(result.Value == null)
              {
            output = false;
              }
              else if(result.Value is bool)
              {
            output = (bool) result.Value;
              }
              else if(result.Value.Equals(0))
              {
            output = false;
              }
              else if(result.Value is IEnumerable)
              {
            var enumerableValue = ((IEnumerable) result.Value).Cast<object>();
            output = enumerableValue.Any();
              }
              else if(result.Value is ITalesConvertible)
              {
            var convertibleValue = (ITalesConvertible) result.Value;
            output = convertibleValue.AsBoolean();
              }
              else
              {
            output = true;
              }

              return output;
        }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:47,代码来源:NotExpressionEvaluator.cs

示例5: Evaluate

        public override ExpressionResult Evaluate(string expression, IRenderingContext context)
        {
            object result;
              ExpressionResult output;

              if(this.TryGetItem(expression, context, out result))
              {
            output = new ExpressionResult(result);
              }
              else
              {
            string message = String.Format(Resources.ExceptionMessages.ModelDoesNotContainItem, expression);
            throw new ModelEvaluationException(message) {
              ElementName = context.Element.Name,
              ExpressionText = expression.ToString(),
            };
              }

              return output;
        }
开发者ID:csf-dev,项目名称:ZPT-Sharp,代码行数:20,代码来源:EmptyModel.cs

示例6: CreateExamples

 private static void CreateExamples(ExpressionResult expression, ICollection<testsuiteType> groupTypes)
 {
     foreach (var group in expression.Examples) {
         var hasGroupErrors = group.Examples.HasErrors();
         var groupType = new testsuiteType
             {
                 name = group.Reason,
                 type = "TestFixture",
                 result = hasGroupErrors ? "Failure" : "Success",
                 executed = bool.TrueString,
                 time = ConvertToSeconds(group.Examples.ElapsedTime()).ToString(CultureInfo.InvariantCulture),
                 asserts = "0",
                 success = hasGroupErrors ? bool.FalseString : bool.TrueString
             };
         var cases = new Collection<testcaseType>();
         CreateErrors(group, cases);
         CreateSuccesses(group, cases);
         groupType.results = cases.ToArray();
         groupTypes.Add(groupType);
     }
 }
开发者ID:alexfalkowski,项目名称:System.Spec,代码行数:21,代码来源:NUnitSpecificationReporter.cs

示例7: Execute

        public ExpressionResult Execute(Expression expression, string exampleText)
        {
            var expressionResult = new ExpressionResult { Name = expression.Name };

            foreach (var exampleGroup in expression.FindExampleGroup(exampleText)) {
                expressionResult.Examples.Add(ExecuteExampleGroup(exampleGroup));

                return expressionResult;
            }

            foreach (var example in expression.FindExample(exampleText)) {
                var exampleResult = new ExampleGroupResult { Reason = example.ExampleGroup.Reason };

                exampleResult.Examples.Add(ExecuteExample(example.ExampleGroup, example.Example));
                expressionResult.Examples.Add(exampleResult);

                return expressionResult;
            }

            expression.Examples.ForEach(group => expressionResult.Examples.Add(ExecuteExampleGroup(group)));

            return expressionResult;
        }
开发者ID:alexfalkowski,项目名称:System.Spec,代码行数:23,代码来源:DefaultExpressionRunner.cs

示例8: HandleMemberReferenceCompletion

		IEnumerable<ICompletionData> HandleMemberReferenceCompletion(ExpressionResult expr)
		{
			if (expr == null)
				return null;

			// do not auto select <number>. (but <number>.<number>.) (0.ToString() is valid)
			if (expr.Node is PrimitiveExpression) {
				var pexpr = (PrimitiveExpression)expr.Node;
				if (!(pexpr.Value is string || pexpr.Value is char) && !pexpr.LiteralValue.Contains('.')) {
					AutoSelect = false;
				}
			}
			var resolveResult = ResolveExpression(expr);

			if (resolveResult == null) {
				return null;
			}
			if (expr.Node is AstType) {

				// check for namespace names
				if (expr.Node.AncestorsAndSelf
					.TakeWhile(n => n is AstType)
					.Any(m => m.Role == NamespaceDeclaration.NamespaceNameRole))
					return null;

				// need to look at paren.parent because of "catch (<Type>.A" expression
				if (expr.Node.Parent != null && expr.Node.Parent.Parent is CatchClause)
					return HandleCatchClauseType(expr);
				return CreateTypeAndNamespaceCompletionData(
					location,
					resolveResult.Result,
					expr.Node,
					resolveResult.Resolver
				);
			}


			return CreateCompletionData(
				location,
				resolveResult.Result,
				expr.Node,
				resolveResult.Resolver
			);
		}
开发者ID:pentp,项目名称:SharpDevelop,代码行数:44,代码来源:CSharpCompletionEngine.cs

示例9: DefaultControlSpaceItems

		IEnumerable<ICompletionData> DefaultControlSpaceItems(ref bool isComplete, ExpressionResult xp = null, bool controlSpace = true)
		{
			var wrapper = new CompletionDataWrapper(this);
			if (offset >= document.TextLength) {
				offset = document.TextLength - 1;
			}
			while (offset > 1 && char.IsWhiteSpace(document.GetCharAt(offset))) {
				offset--;
			}
			location = document.GetLocation(offset);

			if (xp == null) {
				xp = GetExpressionAtCursor();
			}
			AstNode node;
			SyntaxTree unit;
			ExpressionResolveResult rr;
			if (xp != null) {
				node = xp.Node;
				rr = ResolveExpression(node);
				unit = xp.Unit;
			} else {
				unit = ParseStub("foo", false);
				node = unit.GetNodeAt(
					location.Line,
					location.Column + 2,
					n => n is Expression || n is AstType || n is NamespaceDeclaration || n is Attribute
				);
				rr = ResolveExpression(node);
			}
			var ifvisitor = new IfVisitor(location, CompletionContextProvider);
			unit.AcceptVisitor(ifvisitor);
			ifvisitor.End();
			if (!ifvisitor.IsValid)
				return null;
			// namespace name case
			var ns = node as NamespaceDeclaration;
			if (ns != null) {
				var last = ns.NamespaceName;
				if (last != null && location < last.EndLocation)
					return null;
			}
			if (node is Identifier && node.Parent is ForeachStatement) {
				var foreachStmt = (ForeachStatement)node.Parent;
				foreach (var possibleName in GenerateNameProposals (foreachStmt.VariableType)) {
					if (possibleName.Length > 0) {
						wrapper.Result.Add(factory.CreateLiteralCompletionData(possibleName.ToString()));
					}
				}

				AutoSelect = false;
				AutoCompleteEmptyMatch = false;
				isComplete = true;
				return wrapper.Result;
			}

			if (node is Identifier && node.Parent is ParameterDeclaration) {
				if (!controlSpace) {
					return null;
				}
				// Try Parameter name case 
				var param = node.Parent as ParameterDeclaration;
				if (param != null) {
					foreach (var possibleName in GenerateNameProposals (param.Type)) {
						if (possibleName.Length > 0) {
							wrapper.Result.Add(factory.CreateLiteralCompletionData(possibleName.ToString()));
						}
					}
					AutoSelect = false;
					AutoCompleteEmptyMatch = false;
					isComplete = true;
					return wrapper.Result;
				}
			}
			var pDecl = node as ParameterDeclaration;
			if (pDecl != null && pDecl.Parent is LambdaExpression) {
				return null;
			}
			/*						if (Unit != null && (node == null || node is TypeDeclaration)) {
				var constructor = Unit.GetNodeAt<ConstructorDeclaration>(
					location.Line,
					location.Column - 3
				);
				if (constructor != null && !constructor.ColonToken.IsNull && constructor.Initializer.IsNull) {
					wrapper.AddCustom("this");
					wrapper.AddCustom("base");
					return wrapper.Result;
				}
			}*/

			var initializer = node != null ? node.Parent as ArrayInitializerExpression : null;
			if (initializer != null) {
				var result = HandleObjectInitializer(unit, initializer);
				if (result != null)
					return result;
			}
			CSharpResolver csResolver = null;
			if (rr != null) {
				csResolver = rr.Resolver;
			}
//.........这里部分代码省略.........
开发者ID:pentp,项目名称:SharpDevelop,代码行数:101,代码来源:CSharpCompletionEngine.cs

示例10: HandleCatchClauseType

		IEnumerable<ICompletionData> HandleCatchClauseType(ExpressionResult identifierStart)
		{
			Func<IType, IType> typePred = delegate (IType type) {
				if (type.GetAllBaseTypes().Any(t => t.ReflectionName == "System.Exception"))
					return type;
				return null;
			};
			if (identifierStart.Node.Parent is CatchClause) {
				var wrapper = new CompletionDataWrapper(this);
				AddTypesAndNamespaces(
					wrapper,
					GetState(),
					identifierStart.Node,
					typePred,
					m => false
				);
				return wrapper.Result;
			}

			var resolveResult = ResolveExpression(identifierStart);
			return CreateCompletionData(
				location,
				resolveResult.Result,
				identifierStart.Node,
				resolveResult.Resolver,
				typePred
			);
		}
开发者ID:pentp,项目名称:SharpDevelop,代码行数:28,代码来源:CSharpCompletionEngine.cs

示例11: HandleMemberReferenceCompletion

		IEnumerable<ICompletionData> HandleMemberReferenceCompletion(ExpressionResult expr)
		{
			if (expr == null) 
				return null;
		
			// do not complete <number>. (but <number>.<number>.)
			if (expr.Node is PrimitiveExpression) {
				var pexpr = (PrimitiveExpression)expr.Node;
				if (!(pexpr.Value is string || pexpr.Value is char) && !pexpr.LiteralValue.Contains('.')) {
					return null;
				}
			}
			var resolveResult = ResolveExpression(expr);
			if (resolveResult == null) {
				return null;
			}
			if (expr.Node is AstType) {
				// need to look at paren.parent because of "catch (<Type>.A" expression
				if (expr.Node.Parent != null && expr.Node.Parent.Parent is CatchClause)
					return HandleCatchClauseType(expr);
				return CreateTypeAndNamespaceCompletionData(
					location,
					resolveResult.Item1,
					expr.Node,
					resolveResult.Item2
				);
			}
			return CreateCompletionData(
				location,
				resolveResult.Item1,
				expr.Node,
				resolveResult.Item2
			);
		}
开发者ID:DavidS,项目名称:monodevelop,代码行数:34,代码来源:CSharpCompletionEngine.cs

示例12: DefaultControlSpaceItems

		IEnumerable<ICompletionData> DefaultControlSpaceItems(ExpressionResult xp = null, bool controlSpace = true)
		{
			var wrapper = new CompletionDataWrapper(this);
			if (offset >= document.TextLength) {
				offset = document.TextLength - 1;
			}
			while (offset > 1 && char.IsWhiteSpace (document.GetCharAt (offset))) {
				offset--;
			}
			location = document.GetLocation(offset);
			
			if (xp == null) {
				xp = GetExpressionAtCursor();
			}
			AstNode node;
			CompilationUnit unit;
			Tuple<ResolveResult, CSharpResolver> rr;
			if (xp != null) {
				node = xp.Node;
				rr = ResolveExpression(node, xp.Unit);
				unit = xp.Unit;
			} else {
				unit = ParseStub("foo", false);
				node = unit.GetNodeAt(
					location.Line,
					location.Column + 2,
					n => n is Expression || n is AstType
				);
				rr = ResolveExpression(node, unit);
			}
			if (node is Identifier && node.Parent is ForeachStatement) {
				var foreachStmt = (ForeachStatement)node.Parent;
				foreach (var possibleName in GenerateNameProposals (foreachStmt.VariableType)) {
					if (possibleName.Length > 0) {
						wrapper.Result.Add(factory.CreateLiteralCompletionData(possibleName.ToString()));
					}
				}
					
				AutoSelect = false;
				AutoCompleteEmptyMatch = false;
				return wrapper.Result;
			}

			if (node is Identifier && node.Parent is ParameterDeclaration) {
				if (!controlSpace) {
					return null;
				}
				// Try Parameter name case 
				var param = node.Parent as ParameterDeclaration;
				if (param != null) {
					foreach (var possibleName in GenerateNameProposals (param.Type)) {
						if (possibleName.Length > 0) {
							wrapper.Result.Add(factory.CreateLiteralCompletionData(possibleName.ToString()));
						}
					}
					AutoSelect = false;
					AutoCompleteEmptyMatch = false;
					return wrapper.Result;
				}
			}
			if (Unit != null && (node == null || node is TypeDeclaration)) {
				var constructor = Unit.GetNodeAt<ConstructorDeclaration>(
					location.Line,
					location.Column - 3
				);
				if (constructor != null && !constructor.ColonToken.IsNull && constructor.Initializer.IsNull) {
					wrapper.AddCustom("this");
					wrapper.AddCustom("base");
					return wrapper.Result;
				}
			}

			var initializer = node != null ? node.Parent as ArrayInitializerExpression : null;
			if (initializer != null) {
				var result = HandleObjectInitializer(unit, initializer);
				if (result != null)
					return result;
			}
			CSharpResolver csResolver = null;
			if (rr != null) {
				csResolver = rr.Item2;
			}
			if (csResolver == null) {
				if (node != null) {
					csResolver = GetState();
					//var astResolver = new CSharpAstResolver (csResolver, node, xp != null ? xp.Item1 : CSharpParsedFile);
					
					try {
						//csResolver = astResolver.GetResolverStateBefore (node);
						Console.WriteLine(csResolver.LocalVariables.Count());
					} catch (Exception  e) {
						Console.WriteLine("E!!!" + e);
					}
					
				} else {
					csResolver = GetState();
				}
			}
			AddContextCompletion(wrapper, csResolver, node, unit);
			
//.........这里部分代码省略.........
开发者ID:DavidS,项目名称:monodevelop,代码行数:101,代码来源:CSharpCompletionEngine.cs

示例13: ResolveExpression

		protected Tuple<ResolveResult, CSharpResolver> ResolveExpression (ExpressionResult tuple)
		{
			return ResolveExpression (tuple.Node);
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:4,代码来源:CSharpCompletionEngineBase.cs

示例14: HandleMemberReferenceCompletion

		IEnumerable<ICompletionData> HandleMemberReferenceCompletion(ExpressionResult expr)
		{
			if (expr == null) 
				return null;
		
			// do not complete <number>. (but <number>.<number>.)
			if (expr.Node is PrimitiveExpression) {
				var pexpr = (PrimitiveExpression)expr.Node;
				if (!(pexpr.Value is string || pexpr.Value is char) && !pexpr.LiteralValue.Contains('.')) {
					return null;
				}
			}
			
			var resolveResult = ResolveExpression (expr);
			if (resolveResult == null) {
				return null;
			}
			if (expr.Node is AstType) {
				return CreateTypeAndNamespaceCompletionData(location, resolveResult.Item1, expr.Node, resolveResult.Item2);
			}
			return CreateCompletionData(location, resolveResult.Item1, expr.Node, resolveResult.Item2);
		}
开发者ID:txdv,项目名称:monodevelop,代码行数:22,代码来源:CSharpCompletionEngine.cs

示例15: ResolveExpression

		protected ExpressionResolveResult ResolveExpression (ExpressionResult tuple)
		{
			return ResolveExpression (tuple.Node);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:4,代码来源:CSharpCompletionEngineBase.cs


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