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


C# CSharpParser.ParseExpression方法代码示例

本文整理汇总了C#中ICSharpCode.NRefactory.CSharp.CSharpParser.ParseExpression方法的典型用法代码示例。如果您正苦于以下问题:C# CSharpParser.ParseExpression方法的具体用法?C# CSharpParser.ParseExpression怎么用?C# CSharpParser.ParseExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ICSharpCode.NRefactory.CSharp.CSharpParser的用法示例。


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

示例1: CheckSyntax

		public static bool CheckSyntax(string expression, out Error[] errors)
		{
			var p = new CSharpParser();
			p.ParseExpression(expression);
			errors = p.Errors.ToArray();
			return !errors.Any();
		}
开发者ID:dgrunwald,项目名称:SharpDevelop,代码行数:7,代码来源:DebuggerDotCompletion.cs

示例2: ConvertExpression

		string ConvertExpression(string code)
		{
			CSharpParser parser = new CSharpParser();
			var expr = parser.ParseExpression(code);
			Assert.IsFalse(parser.HasErrors);
			return ConvertExpression(expr);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:7,代码来源:CodeDomConvertVisitorTests.cs

示例3: GetNodesBetween

		public void GetNodesBetween()
		{
			var parser = new CSharpParser();
			var expr = parser.ParseExpression("a*b+c*d");
			var nodes = expr.GetNodesBetween(1, 3, 1, 6).ToList();
			Assert.AreEqual(new[] { "b", "+", "c" }, nodes.Select(n => n.ToString()).ToList());
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:7,代码来源:AstTests.cs

示例4: CheckSyntax

		public static bool CheckSyntax(string expression)
		{
			var p = new CSharpParser();
			p.ParseExpression(expression);
			return !p.Errors.Any();
		}
开发者ID:pentp,项目名称:SharpDevelop,代码行数:6,代码来源:DebuggerDotCompletion.cs

示例5: ResolveSnippet

		public ResolveResult ResolveSnippet(ParseInformation parseInfo, TextLocation location, string codeSnippet, ICompilation compilation, CancellationToken cancellationToken)
		{
			var csParseInfo = parseInfo as CSharpFullParseInformation;
			if (csParseInfo == null)
				throw new ArgumentException("Parse info does not have SyntaxTree");
			CSharpAstResolver contextResolver = new CSharpAstResolver(compilation, csParseInfo.SyntaxTree, csParseInfo.UnresolvedFile);
			var node = csParseInfo.SyntaxTree.GetNodeAt(location);
			CSharpResolver context;
			if (node != null)
				context = contextResolver.GetResolverStateAfter(node, cancellationToken);
			else
				context = new CSharpResolver(compilation);
			CSharpParser parser = new CSharpParser();
			var expr = parser.ParseExpression(codeSnippet);
			if (parser.HasErrors)
				return new ErrorResolveResult(SpecialType.UnknownType, PrintErrorsAsString(parser.Errors), TextLocation.Empty);
			CSharpAstResolver snippetResolver = new CSharpAstResolver(context, expr);
			return snippetResolver.Resolve(expr, cancellationToken);
		}
开发者ID:asiazhang,项目名称:SharpDevelop,代码行数:19,代码来源:Parser.cs

示例6: Run

			public void Run()
			{
				try {
					if (searchMode == SearchMode_Literal) {
			      if (1 == searchTerm.Length)
			      {
  						CSharpParser parser = new CSharpParser();
  						PrimitiveExpression pe = parser.ParseExpression(searchTerm[0]) as PrimitiveExpression;
  						if (pe != null && pe.Value != null) {
  							TypeCode peValueType = Type.GetTypeCode(pe.Value.GetType());
  							switch (peValueType) {
  								case TypeCode.Byte:
  								case TypeCode.SByte:
  								case TypeCode.Int16:
  								case TypeCode.UInt16:
  								case TypeCode.Int32:
  								case TypeCode.UInt32:
  								case TypeCode.Int64:
  								case TypeCode.UInt64:
  									searchTermLiteralType = TypeCode.Int64;
  									searchTermLiteralValue = CSharpPrimitiveCast.Cast(TypeCode.Int64, pe.Value, false);
  									break;
  								case TypeCode.Single:
  								case TypeCode.Double:
  								case TypeCode.String:
  									searchTermLiteralType = peValueType;
  									searchTermLiteralValue = pe.Value;
  									break;
  							}
						  }
						}
					}
					
					foreach (var loadedAssembly in assemblies) {
						AssemblyDefinition asm = loadedAssembly.AssemblyDefinition;
						if (asm == null)
							continue;
						CancellationToken cancellationToken = cts.Token;
						foreach (TypeDefinition type in asm.MainModule.Types) {
							cancellationToken.ThrowIfCancellationRequested();
							PerformSearch(type);
						}
					}
				} catch (OperationCanceledException) {
					// ignore cancellation
				}
				// remove the 'Searching...' entry
				dispatcher.BeginInvoke(
					DispatcherPriority.Normal,
					new Action(delegate { this.Results.RemoveAt(this.Results.Count - 1); }));
			}
开发者ID:rongchunzhang,项目名称:ILSpy,代码行数:51,代码来源:SearchPane.cs

示例7: Translate

        private static string[] Translate(string query)
        {
            var parser = new CSharpParser();

            var block = parser.ParseExpression(query);

            var captureQueryParameterNamesVisitor = new CaptureQueryParameterNamesVisitor();
            block.AcceptVisitor(captureQueryParameterNamesVisitor, null);
            return captureQueryParameterNamesVisitor.QueryParameters.ToArray();
        }
开发者ID:j2jensen,项目名称:ravendb,代码行数:10,代码来源:LinqToQueryParameters.cs

示例8: ValidateExpression

		public override ValidationResult ValidateExpression (EvaluationContext ctx, string expression)
		{
			expression = expression.TrimStart ();

			if (expression.Length > 0 && expression[0] == '?')
				expression = expression.Substring (1).Trim ();

			if (expression.StartsWith ("var", StringComparison.Ordinal) && char.IsWhiteSpace (expression[3]))
				expression = expression.Substring (4).Trim ();

			expression = ReplaceExceptionTag (expression, ctx.Options.CurrentExceptionTag);

			// Required as a workaround for a bug in the parser (it won't parse simple expressions like numbers)
			if (!expression.EndsWith (";", StringComparison.Ordinal))
				expression += ";";

			var parser = new CSharpParser ();
			parser.ParseExpression (expression);

			if (parser.HasErrors)
				return new ValidationResult (false, parser.Errors.First ().Message);

			return new ValidationResult (true, null);
		}
开发者ID:IBBoard,项目名称:monodevelop,代码行数:24,代码来源:NRefactoryExpressionEvaluator.cs

示例9: ParseExpression

	/*	public ICSharpCode.OldNRefactory.Parser.Errors LastErrors {
			get;
			private set;
		}*/
		
		public Expression ParseExpression (string expressionText)
		{
			expressionText = expressionText.Trim ();
			var parser = new CSharpParser ();
			Expression result = null;
			try {
				using (var reader = new StringReader (expressionText)) {
					result = parser.ParseExpression (reader) as Expression;
					result.Remove ();
//					LastErrors = parser.Errors;
				}
			} catch (Exception) {
			}
			return result;
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:20,代码来源:CSharpNRefactoryASTProvider.cs

示例10: FormatCSharpExpression

 protected string FormatCSharpExpression(string expression)
 {
     var parser = new CSharpParser();
     parser.ParseExpression(expression + ";");
     if (parser.HasErrors)
     {
         var errors = string.Join(Environment.NewLine, parser.Errors.Select(err => err.Message));
         throw new TemplateParseException(null, string.Format("{0}{1}{2}", expression, Environment.NewLine, errors));
     }
     return expression;
 }
开发者ID:kooboo-jifeng,项目名称:SharpTAL,代码行数:11,代码来源:CodeGenerator.cs


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