本文整理汇总了C#中ICSharpCode.NRefactory.Ast.ParenthesizedExpression类的典型用法代码示例。如果您正苦于以下问题:C# ParenthesizedExpression类的具体用法?C# ParenthesizedExpression怎么用?C# ParenthesizedExpression使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParenthesizedExpression类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了ParenthesizedExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ModifyLambdaForSelectMany
private static INode ModifyLambdaForSelectMany(LambdaExpression lambdaExpression,
ParenthesizedExpression parenthesizedlambdaExpression,
InvocationExpression invocationExpression)
{
INode node = lambdaExpression;
var argPos = invocationExpression.Arguments.IndexOf(lambdaExpression);
switch (argPos)
{
case 0: // first one, select the collection
// need to enter a cast for (IEnumerable<dynamic>) on the end of the lambda body
var selectManyExpression = new LambdaExpression
{
ExpressionBody =
new CastExpression(new TypeReference("IEnumerable<dynamic>"),
new ParenthesizedExpression(lambdaExpression.ExpressionBody), CastType.Cast),
Parameters = lambdaExpression.Parameters,
};
node = new CastExpression(new TypeReference("Func<dynamic, IEnumerable<dynamic>>"),
new ParenthesizedExpression(selectManyExpression), CastType.Cast);
break;
case 1: // the transformation func
node = new CastExpression(new TypeReference("Func<dynamic, dynamic, dynamic>"), parenthesizedlambdaExpression,
CastType.Cast);
break;
}
return node;
}
示例2: GetCastExpression
private CastExpression GetCastExpression(BinaryOperatorExpression binaryOperatorExpression)
{
TypeReference leftType = GetExpressionType(binaryOperatorExpression.Left);
CastExpression castedUnsignedShift = new CastExpression(new TypeReference("u" + leftType.Type), binaryOperatorExpression, CastType.Cast);
ParenthesizedExpression parenthesizedCastedUnsignedShift = new ParenthesizedExpression(castedUnsignedShift);
return new CastExpression(new TypeReference(leftType.Type), parenthesizedCastedUnsignedShift, CastType.Cast);
}
示例3: BuildCondition
/// <summary>
/// Turns "(a.b as T).d.e" into "(a != null) && (a.b is T) && ((a.b as T).d != null)"
/// </summary>
Expression BuildCondition(Expression targetExpr)
{
var parts = GetConditionParts(targetExpr);
Expression condition = null;
foreach (var part in parts) {
if (condition == null) {
// first
condition = new ParenthesizedExpression(part);
} else {
condition = new BinaryOperatorExpression(new ParenthesizedExpression(part), BinaryOperatorType.LogicalAnd, condition);
}
}
return condition;
}
示例4: ModifyLambdaForSelect
private static INode ModifyLambdaForSelect(ParenthesizedExpression parenthesizedlambdaExpression,
MemberReferenceExpression target)
{
var parentInvocation = target.TargetObject as InvocationExpression;
if(parentInvocation != null)
{
var parentTarget = parentInvocation.TargetObject as MemberReferenceExpression;
if(parentTarget != null && parentTarget.MemberName == "GroupBy")
{
return new CastExpression(new TypeReference("Func<IGrouping<dynamic,dynamic>, dynamic>"), parenthesizedlambdaExpression, CastType.Cast);
}
}
return new CastExpression(new TypeReference("Func<dynamic, dynamic>"), parenthesizedlambdaExpression, CastType.Cast);
}
示例5: VisitLambdaExpression
public override object VisitLambdaExpression(ICSharpCode.NRefactory.Ast.LambdaExpression lambdaExpression, object data)
{
var invocationExpression = lambdaExpression.Parent as InvocationExpression;
if (invocationExpression == null)
return base.VisitLambdaExpression(lambdaExpression, data);
var target = invocationExpression.TargetObject as MemberReferenceExpression;
if(target == null)
return base.VisitLambdaExpression(lambdaExpression, data);
INode node = lambdaExpression;
var parenthesizedlambdaExpression = new ParenthesizedExpression(lambdaExpression);
switch (target.MemberName)
{
case "Sum":
case "Average":
node = ModifyLambdaForNumerics(lambdaExpression, parenthesizedlambdaExpression);
break;
case "Max":
case "Min":
node = ModifyLambdaForMinMax(lambdaExpression, parenthesizedlambdaExpression);
break;
case "OrderBy":
case "OrderByDescending":
case "GroupBy":
case "Recurse":
case "Select":
node = ModifyLambdaForSelect(parenthesizedlambdaExpression, target);
break;
case "SelectMany":
node = ModifyLambdaForSelectMany(lambdaExpression, parenthesizedlambdaExpression, invocationExpression);
break;
case "Any":
case "all":
case "First":
case "FirstOrDefault":
case "Last":
case "LastOfDefault":
case "Single":
case "Where":
case "Count":
case "SingleOrDefault":
node = new CastExpression(new TypeReference("Func<dynamic, bool>"), parenthesizedlambdaExpression, CastType.Cast);
break;
}
ReplaceCurrentNode(node);
return base.VisitLambdaExpression(lambdaExpression, data);
}
示例6: GenerateCode
public override void GenerateCode(List<AbstractNode> nodes, IList items)
{
TypeReference intReference = new TypeReference("System.Int32");
MethodDeclaration method = new MethodDeclaration("GetHashCode", Modifiers.Public | Modifiers.Override, intReference, null, null);
Expression expr = CallGetHashCode(new IdentifierExpression(currentClass.Fields[0].Name));
for (int i = 1; i < currentClass.Fields.Count; i++) {
IdentifierExpression identifier = new IdentifierExpression(currentClass.Fields[i].Name);
expr = new BinaryOperatorExpression(expr, BinaryOperatorType.ExclusiveOr,
CallGetHashCode(identifier));
}
method.Body = new BlockStatement();
method.Body.AddChild(new ReturnStatement(expr));
nodes.Add(method);
TypeReference boolReference = new TypeReference("System.Boolean");
TypeReference objectReference = new TypeReference("System.Object");
method = new MethodDeclaration("Equals", Modifiers.Public | Modifiers.Override, boolReference, null, null);
method.Parameters.Add(new ParameterDeclarationExpression(objectReference, "obj"));
method.Body = new BlockStatement();
TypeReference currentType = ConvertType(currentClass.DefaultReturnType);
expr = new TypeOfIsExpression(new IdentifierExpression("obj"), currentType);
expr = new ParenthesizedExpression(expr);
expr = new UnaryOperatorExpression(expr, UnaryOperatorType.Not);
method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(false, "false"))));
expr = new BinaryOperatorExpression(new ThisReferenceExpression(),
BinaryOperatorType.Equality,
new IdentifierExpression("obj"));
method.Body.AddChild(new IfElseStatement(expr, new ReturnStatement(new PrimitiveExpression(true, "true"))));
VariableDeclaration var = new VariableDeclaration("my" + currentClass.Name,
new CastExpression(currentType, new IdentifierExpression("obj"), CastType.Cast),
currentType);
method.Body.AddChild(new LocalVariableDeclaration(var));
expr = TestEquality(var.Name, currentClass.Fields[0]);
for (int i = 1; i < currentClass.Fields.Count; i++) {
expr = new BinaryOperatorExpression(expr, BinaryOperatorType.LogicalAnd,
TestEquality(var.Name, currentClass.Fields[i]));
}
method.Body.AddChild(new ReturnStatement(expr));
nodes.Add(method);
}
示例7: TrackedVisitParenthesizedExpression
public virtual object TrackedVisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) {
return base.VisitParenthesizedExpression(parenthesizedExpression, data);
}
示例8: SimpleNonInvocationExpression
void SimpleNonInvocationExpression(
#line 1645 "VBNET.ATG"
out Expression pexpr) {
#line 1647 "VBNET.ATG"
Expression expr;
TypeReference type = null;
string name = String.Empty;
pexpr = null;
if (StartOf(32)) {
switch (la.kind) {
case 3: {
lexer.NextToken();
#line 1655 "VBNET.ATG"
pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };
break;
}
case 4: {
lexer.NextToken();
#line 1656 "VBNET.ATG"
pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };
break;
}
case 7: {
lexer.NextToken();
#line 1657 "VBNET.ATG"
pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };
break;
}
case 6: {
lexer.NextToken();
#line 1658 "VBNET.ATG"
pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };
break;
}
case 5: {
lexer.NextToken();
#line 1659 "VBNET.ATG"
pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };
break;
}
case 9: {
lexer.NextToken();
#line 1660 "VBNET.ATG"
pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };
break;
}
case 8: {
lexer.NextToken();
#line 1661 "VBNET.ATG"
pexpr = new PrimitiveExpression(t.literalValue, t.val) { LiteralFormat = t.literalFormat };
break;
}
case 202: {
lexer.NextToken();
#line 1663 "VBNET.ATG"
pexpr = new PrimitiveExpression(true, "true");
break;
}
case 109: {
lexer.NextToken();
#line 1664 "VBNET.ATG"
pexpr = new PrimitiveExpression(false, "false");
break;
}
case 151: {
lexer.NextToken();
#line 1665 "VBNET.ATG"
pexpr = new PrimitiveExpression(null, "null");
break;
}
case 25: {
lexer.NextToken();
Expr(
#line 1666 "VBNET.ATG"
out expr);
Expect(26);
#line 1666 "VBNET.ATG"
pexpr = new ParenthesizedExpression(expr);
break;
}
case 2: case 45: case 49: case 51: case 52: case 53: case 54: case 57: case 74: case 85: case 91: case 94: case 103: case 108: case 113: case 120: case 126: case 130: case 133: case 156: case 162: case 169: case 188: case 197: case 198: case 208: case 209: case 215: {
Identifier();
#line 1668 "VBNET.ATG"
pexpr = new IdentifierExpression(t.val);
pexpr.StartLocation = t.Location; pexpr.EndLocation = t.EndLocation;
//.........这里部分代码省略.........
示例9: VisitParenthesizedExpression
public virtual object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data) {
throw new global::System.NotImplementedException("ParenthesizedExpression");
}
示例10: VisitParenthesizedExpression
public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
{
return Evaluate(parenthesizedExpression.Expression);
}
示例11: VisitParenthesizedExpression
public override object VisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
{
base.VisitParenthesizedExpression(parenthesizedExpression, data);
if (parenthesizedExpression.Expression is CastExpression) {
ReplaceCurrentNode(parenthesizedExpression.Expression); // remove parenthesis around casts
} else if (parenthesizedExpression.Parent is CastExpression) {
ReplaceCurrentNode(parenthesizedExpression.Expression); // remove parenthesis inside casts
}
return null;
}
示例12: ModifyLambdaForNumerics
private static INode ModifyLambdaForNumerics(LambdaExpression lambdaExpression,
ParenthesizedExpression parenthesizedlambdaExpression)
{
var castExpression = lambdaExpression.ExpressionBody as CastExpression;
if (castExpression != null)
{
return new CastExpression(new TypeReference("Func", new List<TypeReference>
{
new TypeReference("dynamic"),
castExpression.CastTo
}), parenthesizedlambdaExpression, CastType.Cast);
}
var expression = new LambdaExpression
{
ExpressionBody = new CastExpression(new TypeReference("decimal",isKeyword:true), new ParenthesizedExpression(lambdaExpression.ExpressionBody), CastType.Cast),
Parameters = lambdaExpression.Parameters
};
return new CastExpression(new TypeReference("Func<dynamic, decimal>"),
new ParenthesizedExpression(expression), CastType.Cast);
}
示例13: VisitExpression
public void VisitExpression (ParenthesizedExpression expression, MethodProperties meth)
{
VisitExpression(((ParenthesizedExpression)expression).Expression, meth);
}
示例14: VisitParenthesizedExpression
public override object VisitParenthesizedExpression (ParenthesizedExpression parenthesizedExpression, object data)
{
if (parenthesizedExpression == null)
return null;
return parenthesizedExpression.Expression.AcceptVisitor (this, data);
}
示例15: TrackedVisitParenthesizedExpression
public override object TrackedVisitParenthesizedExpression(ParenthesizedExpression parenthesizedExpression, object data)
{
this.Append("(");
parenthesizedExpression.Expression.AcceptVisitor(this, data);
this.Append(")");
return null;
}