private static ExpressionToken Visit(NewExpression exp) { CompositeExpressionToken token = new CompositeExpressionToken(); Type declaringType = exp.Type; if (exp.Constructor != null) { declaringType = exp.Constructor.DeclaringType; } token.AddStringToken("new " + (declaringType.IsAnonymous() ? "" : declaringType.FormatTypeName()) + ((exp.Arguments.Count == 0) ? "" : " ")); if ((exp.Members == null) || (exp.Members.Count == 0)) { CompositeExpressionToken token2 = new CompositeExpressionToken(from a in exp.Arguments select Visit(a), true); token.Tokens.Add(new BracketedExpressionToken("(", ")", token2)); return(token); } int num = 0; CompositeExpressionToken body = new CompositeExpressionToken { MultiLine = true, AddCommas = true }; foreach (Expression expression in exp.Arguments) { MemberInfo mi = exp.Members[num++]; PropertyInfo info = mi as PropertyInfo; if (info == null) { info = mi.DeclaringType.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).FirstOrDefault <PropertyInfo>(p => p.GetAccessors().Contains <MemberInfo>(mi)); } if (info != null) { CompositeExpressionToken token5 = new CompositeExpressionToken(); token5.AddStringToken(CleanIdentifier(info.Name) + " = "); token5.Tokens.Add(Visit(expression)); token5.Splittable = true; body.Tokens.Add(token5); } } BracketedExpressionToken item = new BracketedExpressionToken("{", "}", body) { NewLineBefore = true }; token.Tokens.Add(item); return(token); }
private static ExpressionToken Visit(MemberInitExpression exp) { CompositeExpressionToken token = new CompositeExpressionToken(); if (exp.NewExpression.Type.IsAnonymous()) { token.AddStringToken("new "); } else { token.Tokens.Add(Visit(exp.NewExpression)); } CompositeExpressionToken body = new CompositeExpressionToken(from b in exp.Bindings select Visit(b), true) { MultiLine = true }; BracketedExpressionToken item = new BracketedExpressionToken("{", "}", body) { NewLineBefore = true }; token.Tokens.Add(item); return(token); }
private static ExpressionToken Visit(NewExpression exp) { CompositeExpressionToken token = new CompositeExpressionToken(); Type declaringType = exp.Type; if (exp.Constructor != null) { declaringType = exp.Constructor.DeclaringType; } token.AddStringToken("new " + (declaringType.IsAnonymous() ? "" : declaringType.FormatTypeName()) + ((exp.Arguments.Count == 0) ? "" : " ")); if ((exp.Members == null) || (exp.Members.Count == 0)) { CompositeExpressionToken token2 = new CompositeExpressionToken(from a in exp.Arguments select Visit(a), true); token.Tokens.Add(new BracketedExpressionToken("(", ")", token2)); return token; } int num = 0; CompositeExpressionToken body = new CompositeExpressionToken { MultiLine = true, AddCommas = true }; foreach (Expression expression in exp.Arguments) { MemberInfo mi = exp.Members[num++]; PropertyInfo info = mi as PropertyInfo; if (info == null) { info = mi.DeclaringType.GetProperties(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance).FirstOrDefault<PropertyInfo>(p => p.GetAccessors().Contains<MemberInfo>(mi)); } if (info != null) { CompositeExpressionToken token5 = new CompositeExpressionToken(); token5.AddStringToken(CleanIdentifier(info.Name) + " = "); token5.Tokens.Add(Visit(expression)); token5.Splittable = true; body.Tokens.Add(token5); } } BracketedExpressionToken item = new BracketedExpressionToken("{", "}", body) { NewLineBefore = true }; token.Tokens.Add(item); return token; }
private static ExpressionToken Visit(MemberInitExpression exp) { CompositeExpressionToken token = new CompositeExpressionToken(); if (exp.NewExpression.Type.IsAnonymous()) { token.AddStringToken("new "); } else { token.Tokens.Add(Visit(exp.NewExpression)); } CompositeExpressionToken body = new CompositeExpressionToken(from b in exp.Bindings select Visit(b), true) { MultiLine = true }; BracketedExpressionToken item = new BracketedExpressionToken("{", "}", body) { NewLineBefore = true }; token.Tokens.Add(item); return token; }