本文整理汇总了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();
}
示例2: ConvertExpression
string ConvertExpression(string code)
{
CSharpParser parser = new CSharpParser();
var expr = parser.ParseExpression(code);
Assert.IsFalse(parser.HasErrors);
return ConvertExpression(expr);
}
示例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());
}
示例4: CheckSyntax
public static bool CheckSyntax(string expression)
{
var p = new CSharpParser();
p.ParseExpression(expression);
return !p.Errors.Any();
}
示例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);
}
示例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); }));
}
示例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();
}
示例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);
}
示例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;
}
示例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;
}