本文整理汇总了C#中Expression.AcceptVisitor方法的典型用法代码示例。如果您正苦于以下问题:C# Expression.AcceptVisitor方法的具体用法?C# Expression.AcceptVisitor怎么用?C# Expression.AcceptVisitor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Expression
的用法示例。
在下文中一共展示了Expression.AcceptVisitor方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InsertRequired
string InsertRequired(Expression expr)
{
expr = expr.Clone();
expr.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = false }, null);
StringWriter w = new StringWriter();
expr.AcceptVisitor(new OutputVisitor(w, policy), null);
return w.ToString();
}
示例2: InsertRequired
string InsertRequired(Expression expr)
{
expr = expr.Clone();
expr.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = false }, null);
StringWriter w = new StringWriter();
w.NewLine = " ";
expr.AcceptVisitor(new OutputVisitor(new TextWriterOutputFormatter(w) { IndentationString = "" }, policy), null);
return w.ToString();
}
示例3: InsertReadable
string InsertReadable(Expression expr)
{
expr = expr.Clone();
expr.AcceptVisitor(new InsertParenthesesVisitor { InsertParenthesesForReadability = true });
StringWriter w = new StringWriter();
w.NewLine = " ";
expr.AcceptVisitor(new CSharpOutputVisitor(new TextWriterOutputFormatter(w) { IndentationString = "" }, policy));
return w.ToString();
}
示例4: AssertOutput
void AssertOutput(string expected, Expression expr, CSharpFormattingOptions policy = null)
{
if (policy == null)
policy = new CSharpFormattingOptions();;
StringWriter w = new StringWriter();
w.NewLine = "\n";
expr.AcceptVisitor(new CSharpOutputVisitor(new TextWriterOutputFormatter(w) { IndentationString = "\t" }, policy), null);
Assert.AreEqual(expected.Replace("\r", ""), w.ToString());
}
示例5: Analyze
public static List<IVariable> Analyze(RefactoringContext context, Expression expression)
{
var visitor = new VariableLookupVisitor(context);
expression.AcceptVisitor(visitor);
return visitor.UsedVariables;
}
示例6: EmitNameExpression
protected virtual void EmitNameExpression(string name, Expression namedExpression, Expression expression)
{
var resolveResult = this.Emitter.Resolver.ResolveNode(namedExpression, this.Emitter);
if (!this.Emitter.AssemblyInfo.PreserveMemberCase)
{
name = Object.Net.Utilities.StringUtils.ToLowerCamelCase(name);
}
if (resolveResult != null && resolveResult is MemberResolveResult)
{
var member = ((MemberResolveResult)resolveResult).Member;
var preserveCase = !this.Emitter.IsNativeMember(member.FullName) ? this.Emitter.AssemblyInfo.PreserveMemberCase : false;
name = this.Emitter.GetEntityName(member, preserveCase);
var isProperty = member.SymbolKind == SymbolKind.Property;
if (!isProperty)
{
this.Write(name);
}
else
{
this.Write(isProperty ? Helpers.GetPropertyRef(member, this.Emitter, !(expression is ArrayInitializerExpression)) : name);
}
}
else
{
this.Write(name);
}
this.WriteColon();
expression.AcceptVisitor(this.Emitter);
}
示例7: Check
void Check (Expression expression)
{
if (expression is BinaryOperatorExpression) {
expression.AcceptVisitor(this);
return;
}
if (stringExpressionCount <= 1) {
var resolveResult = issue.ctx.Resolve(expression);
if (resolveResult.Type.IsKnownType(KnownTypeCode.String)) {
stringExpressionCount++;
if (stringExpressionCount == 1) {
firstStringExpression = expression;
} else {
issue.CheckExpressionInAutoCallContext(firstStringExpression);
issue.CheckExpressionInAutoCallContext(expression);
}
}
} else {
issue.CheckExpressionInAutoCallContext(expression);
}
}
示例8: EmitCastExpression
protected virtual void EmitCastExpression(Expression expression, AstType type, string method)
{
var castToEnum = this.Emitter.BridgeTypes.ToType(type).Kind == TypeKind.Enum;
if (method != Bridge.Translator.Emitter.IS && (Helpers.IsIgnoreCast(type, this.Emitter) || castToEnum))
{
expression.AcceptVisitor(this.Emitter);
return;
}
if (method == Bridge.Translator.Emitter.IS && castToEnum)
{
this.Write("Bridge.hasValue(");
expression.AcceptVisitor(this.Emitter);
this.Write(")");
return;
}
var expressionrr = this.Emitter.Resolver.ResolveNode(expression, this.Emitter);
var typerr = this.Emitter.Resolver.ResolveNode(type, this.Emitter);
if (expressionrr.Type.Equals(typerr.Type))
{
if (method == Bridge.Translator.Emitter.IS)
{
this.WriteScript(true);
}
else
{
expression.AcceptVisitor(this.Emitter);
}
return;
}
bool isInlineCast;
string castCode = this.GetCastCode(expression, type, out isInlineCast);
bool isNullable = NullableType.IsNullable(expressionrr.Type);
bool isResultNullable = NullableType.IsNullable(typerr.Type);
if (isInlineCast)
{
if (isNullable)
{
isNullable = !NullableType.GetUnderlyingType(expressionrr.Type).Equals(typerr.Type);
}
this.EmitInlineCast(expression, type, castCode, isNullable, isResultNullable);
return;
}
if (method == Bridge.Translator.Emitter.CAST)
{
if (Helpers.IsIntegerType(typerr.Type, this.Emitter.Resolver))
{
if (expressionrr.Type != null && Helpers.IsFloatType(expressionrr.Type, this.Emitter.Resolver))
{
this.Write("Bridge.Int.trunc(");
if (isNullable && !isResultNullable)
{
this.Write("Bridge.Nullable.getValue(");
}
expression.AcceptVisitor(this.Emitter);
if (isNullable && !isResultNullable)
{
this.WriteCloseParentheses();
}
this.Write(")");
return;
}
}
if (ConversionBlock.IsUserDefinedConversion(this, this.CastExpression.Expression))
{
expression.AcceptVisitor(this.Emitter);
return;
}
}
var simpleType = type as SimpleType;
bool hasValue = false;
if (simpleType != null && simpleType.Identifier == "dynamic")
{
if (method == Bridge.Translator.Emitter.CAST || method == Bridge.Translator.Emitter.AS)
{
expression.AcceptVisitor(this.Emitter);
return;
}
else if (method == Bridge.Translator.Emitter.IS)
{
hasValue = true;
method = "hasValue";
}
}
this.Write(Bridge.Translator.Emitter.ROOT);
this.WriteDot();
//.........这里部分代码省略.........
示例9: EmitInlineCast
protected virtual void EmitInlineCast(Expression expression, AstType astType, string castCode, bool isNullable, bool isResultNullable)
{
this.Write("");
var name = "{" + this.InlineMethod.Parameters[0].Name + "}";
if (!castCode.Contains(name))
{
name = "{this}";
}
if (castCode.Contains(name))
{
var oldBuilder = this.Emitter.Output;
this.Emitter.Output = new StringBuilder();
if (isNullable && !isResultNullable)
{
this.Write("Bridge.Nullable.getValue(");
}
expression.AcceptVisitor(this.Emitter);
if (isNullable && !isResultNullable)
{
this.WriteCloseParentheses();
}
castCode = castCode.Replace(name, this.Emitter.Output.ToString());
this.Emitter.Output = oldBuilder;
}
if (castCode.Contains("{0}"))
{
var oldBuilder = this.Emitter.Output;
this.Emitter.Output = new StringBuilder();
this.EmitCastType(astType);
castCode = castCode.Replace("{0}", this.Emitter.Output.ToString());
this.Emitter.Output = oldBuilder;
}
this.Write(castCode);
}
示例10: CheckForInvocations
bool CheckForInvocations(Expression initializer)
{
var visitor = new CheckInitializer();
initializer.AcceptVisitor(visitor);
return visitor.IsValid;
}
示例11: Evaluate
public bool Evaluate(Expression condition)
{
return condition.AcceptVisitor(this, null) == SymbolDefined;
}
示例12: EmitNameExpression
protected virtual void EmitNameExpression(string name, Expression namedExpression, Expression expression)
{
var resolveResult = this.Emitter.Resolver.ResolveNode(namedExpression, this.Emitter);
var lowerCaseName = this.Emitter.ChangeCase ? Object.Net.Utilities.StringUtils.ToLowerCamelCase(name) : name;
if (resolveResult != null && resolveResult is MemberResolveResult)
{
var member = ((MemberResolveResult)resolveResult).Member;
lowerCaseName = this.Emitter.GetEntityName(member);
var isProperty = member.SymbolKind == SymbolKind.Property;
if (!isProperty)
{
this.Write(lowerCaseName);
}
else
{
this.Write(isProperty ? Helpers.GetPropertyRef(member, this.Emitter, !(expression is ArrayInitializerExpression)) : lowerCaseName);
}
}
else
{
this.Write(lowerCaseName);
}
this.WriteColon();
expression.AcceptVisitor(this.Emitter);
}
示例13: ConvertExpression
B.Expression ConvertExpression(Expression expr)
{
if (expr.IsNull)
return null;
return (B.Expression)expr.AcceptVisitor(this, null);
}
示例14: AddEventHandler
void AddEventHandler(Expression eventExpr, Expression handler, object data)
{
methodReference = true;
CodeExpression methodInvoker = (CodeExpression)handler.AcceptVisitor(this, data);
methodReference = false;
if (!(methodInvoker is CodeObjectCreateExpression)) {
// we need to create an event handler here
methodInvoker = new CodeObjectCreateExpression(new CodeTypeReference("System.EventHandler"), methodInvoker);
}
if (eventExpr is IdentifierExpression) {
AddStmt(new CodeAttachEventStatement(new CodeEventReferenceExpression(new CodeThisReferenceExpression(), ((IdentifierExpression)eventExpr).Identifier),
methodInvoker));
} else {
MemberReferenceExpression fr = (MemberReferenceExpression)eventExpr;
AddStmt(new CodeAttachEventStatement(new CodeEventReferenceExpression((CodeExpression)fr.TargetObject.AcceptVisitor(this, data), fr.MemberName),
methodInvoker));
}
}