internal virtual SqlExpression VisitMethodCall(SqlMethodCall mc) { mc.Object = this.VisitExpression(mc.Object); int num = 0; int count = mc.Arguments.Count; while (num < count) { mc.Arguments[num] = this.VisitExpression(mc.Arguments[num]); num++; } return(mc); }
internal override SqlExpression VisitMethodCall(SqlMethodCall mc) { SqlExpression[] args = new SqlExpression[mc.Arguments.Count]; int index = 0; int count = mc.Arguments.Count; while (index < count) { args[index] = this.VisitExpression(mc.Arguments[index]); index++; } return(new SqlMethodCall(mc.ClrType, mc.SqlType, mc.Method, this.VisitExpression(mc.Object), args, mc.SourceExpression)); }
internal override SqlExpression VisitMethodCall(SqlMethodCall mc) { mc.Object = this.VisitExpression(mc.Object); System.Reflection.ParameterInfo[] parameters = mc.Method.GetParameters(); int index = 0; int count = mc.Arguments.Count; while (index < count) { mc.Arguments[index] = this.VisitNamedExpression(mc.Arguments[index], parameters[index].Name); index++; } return(mc); }
private SqlExpression TranslateVbIIF(SqlMethodCall mc) { if (mc.Arguments[1].ClrType != mc.Arguments[2].ClrType) { throw Error.IifReturnTypesMustBeEqual(mc.Arguments[1].ClrType.Name, mc.Arguments[2].ClrType.Name); } var list = new List <SqlWhen>(1) { new SqlWhen(mc.Arguments[0], mc.Arguments[1]) }; var @else = mc.Arguments[2]; while (@else.NodeType == SqlNodeType.SearchedCase) { var @case = (SqlSearchedCase)@else; list.AddRange(@case.Whens); @else = @case.Else; } return(this.sql.SearchedCase(list.ToArray(), @else, mc.SourceExpression)); }
private static bool IsSupportedMethod(SqlMethodCall mc) { if (mc.Method.IsStatic) { switch (mc.Method.Name) { case "op_Equality": case "op_Inequality": case "op_LessThan": case "op_LessThanOrEqual": case "op_GreaterThan": case "op_GreaterThanOrEqual": case "op_Multiply": case "op_Division": case "op_Subtraction": case "op_Addition": case "op_Modulus": case "op_BitwiseAnd": case "op_BitwiseOr": case "op_ExclusiveOr": case "op_UnaryNegation": case "op_OnesComplement": case "op_False": return(true); case "Equals": return(mc.Arguments.Count == 2); case "Concat": return(mc.Method.DeclaringType == typeof(string)); } return(false); } return(((mc.Method.Name == "Equals") && (mc.Arguments.Count == 1)) || ((mc.Method.Name == "GetType") && (mc.Arguments.Count == 0))); }
private static bool IsCompareToMethod(SqlMethodCall call) { return(((!call.Method.IsStatic && (call.Method.Name == "CompareTo")) && (call.Arguments.Count == 1)) && (call.Method.ReturnType == typeof(int))); }
internal override SqlExpression VisitMethodCall(SqlMethodCall mc) { mc.Object = this.VisitExpression(mc.Object); int num = 0; int count = mc.Arguments.Count; while (num < count) { mc.Arguments[num] = this.VisitExpression(mc.Arguments[num]); num++; } if (mc.Method.IsStatic) { if ((mc.Method.Name == "Equals") && (mc.Arguments.Count == 2)) { return(this.sql.Binary(SqlNodeType.EQ2V, mc.Arguments[0], mc.Arguments[1], mc.Method)); } if ((mc.Method.DeclaringType == typeof(string)) && (mc.Method.Name == "Concat")) { SqlExpression expression; var array = mc.Arguments[0] as SqlClientArray; var expressions = array != null ? array.Expressions : mc.Arguments; if (expressions.Count == 0) { return(this.sql.ValueFromObject("", false, mc.SourceExpression)); } if (expressions[0].SqlType.IsString || expressions[0].SqlType.IsChar) { expression = expressions[0]; } else { expression = this.sql.ConvertTo(typeof(string), expressions[0]); } for (int i = 1; i < expressions.Count; i++) { if (expressions[i].SqlType.IsString || expressions[i].SqlType.IsChar) { expression = this.sql.Concat(new SqlExpression[] { expression, expressions[i] }, mc.SourceExpression); } else { expression = this.sql.Concat(new SqlExpression[] { expression, this.sql.ConvertTo(typeof(string), expressions[i]) }, mc.SourceExpression); } } return(expression); } if (PreBindDotNetConverter.IsVbIIF(mc)) { return(this.TranslateVbIIF(mc)); } switch (mc.Method.Name) { case "op_Equality": return(this.sql.Binary(SqlNodeType.EQ, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_Inequality": return(this.sql.Binary(SqlNodeType.NE, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_LessThan": return(this.sql.Binary(SqlNodeType.LT, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_LessThanOrEqual": return(this.sql.Binary(SqlNodeType.LE, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_GreaterThan": return(this.sql.Binary(SqlNodeType.GT, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_GreaterThanOrEqual": return(this.sql.Binary(SqlNodeType.GE, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_Multiply": return(this.sql.Binary(SqlNodeType.Mul, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_Division": return(this.sql.Binary(SqlNodeType.Div, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_Subtraction": return(this.sql.Binary(SqlNodeType.Sub, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_Addition": return(this.sql.Binary(SqlNodeType.Add, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_Modulus": return(this.sql.Binary(SqlNodeType.Mod, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_BitwiseAnd": return(this.sql.Binary(SqlNodeType.BitAnd, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_BitwiseOr": return(this.sql.Binary(SqlNodeType.BitOr, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_ExclusiveOr": return(this.sql.Binary(SqlNodeType.BitXor, mc.Arguments[0], mc.Arguments[1], mc.Method, mc.ClrType)); case "op_UnaryNegation": return(this.sql.Unary(SqlNodeType.Negate, mc.Arguments[0], mc.Method, mc.SourceExpression)); case "op_OnesComplement": return(this.sql.Unary(SqlNodeType.BitNot, mc.Arguments[0], mc.Method, mc.SourceExpression)); case "op_False": return(this.sql.Unary(SqlNodeType.Not, mc.Arguments[0], mc.Method, mc.SourceExpression)); } return(mc); } if ((mc.Method.Name == "Equals") && (mc.Arguments.Count == 1)) { return(this.sql.Binary(SqlNodeType.EQ, mc.Object, mc.Arguments[0])); } if (!(mc.Method.Name == "GetType") || (mc.Arguments.Count != 0)) { return(mc); } MetaType sourceMetaType = TypeSource.GetSourceMetaType(mc.Object, this.model); if (sourceMetaType.HasInheritance) { Type type = sourceMetaType.Discriminator.Type; var discriminator = new SqlDiscriminatorOf(mc.Object, type, this.sql.TypeProvider.From(type), mc.SourceExpression); return(this.VisitExpression(this.sql.DiscriminatedType(discriminator, sourceMetaType))); } return(this.VisitExpression(this.sql.StaticType(sourceMetaType, mc.SourceExpression))); }
private static bool IsVbIIF(SqlMethodCall mc) { return((mc.Method.IsStatic && (mc.Method.DeclaringType.FullName == "Microsoft.VisualBasic.Interaction")) && (mc.Method.Name == "IIf")); }
private static bool IsVbCompareString(SqlMethodCall call) { return((call.Method.IsStatic && (call.Method.DeclaringType.FullName == "Microsoft.VisualBasic.CompilerServices.Operators")) && (call.Method.Name == "CompareString")); }
private static bool IsSupportedVbHelperMethod(SqlMethodCall mc) { return(IsVbIIF(mc)); }
private SqlExpression ExpandTogether(IList <SqlExpression> exprs) { switch (exprs[0].NodeType) { case SqlNodeType.Element: case SqlNodeType.Grouping: case SqlNodeType.ClientQuery: case SqlNodeType.Multiset: throw Error.UnionWithHierarchy(); case SqlNodeType.Link: { SqlLink[] linkArray = new SqlLink[exprs.Count]; linkArray[0] = (SqlLink)exprs[0]; int index = 1; int count = exprs.Count; while (index < count) { if ((exprs[index] == null) || (exprs[index].NodeType != SqlNodeType.Link)) { throw Error.UnionIncompatibleConstruction(); } linkArray[index] = (SqlLink)exprs[index]; if (((linkArray[index].KeyExpressions.Count != linkArray[0].KeyExpressions.Count) || (linkArray[index].Member != linkArray[0].Member)) || ((linkArray[index].Expansion != null) != (linkArray[0].Expansion != null))) { throw Error.UnionIncompatibleConstruction(); } index++; } SqlExpression[] keyExpressions = new SqlExpression[linkArray[0].KeyExpressions.Count]; List <SqlExpression> list11 = new List <SqlExpression>(); int num29 = 0; int num30 = linkArray[0].KeyExpressions.Count; while (num29 < num30) { list11.Clear(); int num31 = 0; int num32 = exprs.Count; while (num31 < num32) { list11.Add(linkArray[num31].KeyExpressions[num29]); num31++; } keyExpressions[num29] = this.ExpandTogether(list11); int num33 = 0; int num34 = exprs.Count; while (num33 < num34) { linkArray[num33].KeyExpressions[num29] = list11[num33]; num33++; } num29++; } SqlExpression expansion = null; if (linkArray[0].Expansion != null) { list11.Clear(); int num35 = 0; int num36 = exprs.Count; while (num35 < num36) { list11.Add(linkArray[num35].Expansion); num35++; } expansion = this.ExpandTogether(list11); int num37 = 0; int num38 = exprs.Count; while (num37 < num38) { linkArray[num37].Expansion = list11[num37]; num37++; } } return(new SqlLink(linkArray[0].Id, linkArray[0].RowType, linkArray[0].ClrType, linkArray[0].SqlType, linkArray[0].Expression, linkArray[0].Member, keyExpressions, expansion, linkArray[0].SourceExpression)); } case SqlNodeType.ClientCase: { SqlClientCase[] caseArray = new SqlClientCase[exprs.Count]; caseArray[0] = (SqlClientCase)exprs[0]; for (int i = 1; i < caseArray.Length; i++) { caseArray[i] = (SqlClientCase)exprs[i]; } List <SqlExpression> list3 = new List <SqlExpression>(); for (int j = 0; j < caseArray.Length; j++) { list3.Add(caseArray[j].Expression); } SqlExpression expr = this.ExpandTogether(list3); List <SqlClientWhen> whens = new List <SqlClientWhen>(); for (int k = 0; k < caseArray[0].Whens.Count; k++) { List <SqlExpression> list5 = new List <SqlExpression>(); for (int m = 0; m < caseArray.Length; m++) { SqlClientWhen when = caseArray[m].Whens[k]; list5.Add(when.Value); } whens.Add(new SqlClientWhen(caseArray[0].Whens[k].Match, this.ExpandTogether(list5))); } return(new SqlClientCase(caseArray[0].ClrType, expr, whens, caseArray[0].SourceExpression)); } case SqlNodeType.DiscriminatedType: { SqlDiscriminatedType type = (SqlDiscriminatedType)exprs[0]; List <SqlExpression> list15 = new List <SqlExpression>(exprs.Count); list15.Add(type.Discriminator); int num44 = 1; int num45 = exprs.Count; while (num44 < num45) { SqlDiscriminatedType type2 = (SqlDiscriminatedType)exprs[num44]; if (type2.TargetType != type.TargetType) { throw Error.UnionIncompatibleConstruction(); } list15.Add(type2.Discriminator); num44++; } return(this.factory.DiscriminatedType(this.ExpandTogether(list15), ((SqlDiscriminatedType)exprs[0]).TargetType)); } case SqlNodeType.MethodCall: { SqlMethodCall[] callArray = new SqlMethodCall[exprs.Count]; for (int n = 0; n < callArray.Length; n++) { callArray[n] = (SqlMethodCall)exprs[n]; } List <SqlExpression> list = new List <SqlExpression>(); for (int num2 = 0; num2 < callArray[0].Arguments.Count; num2++) { List <SqlExpression> list2 = new List <SqlExpression>(); for (int num3 = 0; num3 < callArray.Length; num3++) { list2.Add(callArray[num3].Arguments[num2]); } SqlExpression item = this.ExpandTogether(list2); list.Add(item); } return(this.factory.MethodCall(callArray[0].Method, callArray[0].Object, list.ToArray(), callArray[0].SourceExpression)); } case SqlNodeType.New: { SqlNew[] newArray = new SqlNew[exprs.Count]; newArray[0] = (SqlNew)exprs[0]; int num13 = 1; int num14 = exprs.Count; while (num13 < num14) { if ((exprs[num13] == null) || (exprs[num13].NodeType != SqlNodeType.New)) { throw Error.UnionIncompatibleConstruction(); } newArray[num13] = (SqlNew)exprs[1]; if (newArray[num13].Members.Count != newArray[0].Members.Count) { throw Error.UnionDifferentMembers(); } int num15 = 0; int num16 = newArray[0].Members.Count; while (num15 < num16) { if (newArray[num13].Members[num15].Member != newArray[0].Members[num15].Member) { throw Error.UnionDifferentMemberOrder(); } num15++; } num13++; } SqlMemberAssign[] bindings = new SqlMemberAssign[newArray[0].Members.Count]; int num17 = 0; int length = bindings.Length; while (num17 < length) { List <SqlExpression> list9 = new List <SqlExpression>(); int num19 = 0; int num20 = exprs.Count; while (num19 < num20) { list9.Add(newArray[num19].Members[num17].Expression); num19++; } bindings[num17] = new SqlMemberAssign(newArray[0].Members[num17].Member, this.ExpandTogether(list9)); int num21 = 0; int num22 = exprs.Count; while (num21 < num22) { newArray[num21].Members[num17].Expression = list9[num21]; num21++; } num17++; } SqlExpression[] args = new SqlExpression[newArray[0].Args.Count]; int num23 = 0; int num24 = args.Length; while (num23 < num24) { List <SqlExpression> list10 = new List <SqlExpression>(); int num25 = 0; int num26 = exprs.Count; while (num25 < num26) { list10.Add(newArray[num25].Args[num23]); num25++; } args[num23] = this.ExpandTogether(list10); num23++; } return(this.factory.New(newArray[0].MetaType, newArray[0].Constructor, args, newArray[0].ArgMembers, bindings, exprs[0].SourceExpression)); } case SqlNodeType.OptionalValue: { if (exprs[0].SqlType.CanBeColumn) { break; } List <SqlExpression> list12 = new List <SqlExpression>(exprs.Count); List <SqlExpression> list13 = new List <SqlExpression>(exprs.Count); int num40 = 0; int num41 = exprs.Count; while (num40 < num41) { if ((exprs[num40] == null) || (exprs[num40].NodeType != SqlNodeType.OptionalValue)) { throw Error.UnionIncompatibleConstruction(); } SqlOptionalValue value4 = (SqlOptionalValue)exprs[num40]; list12.Add(value4.HasValue); list13.Add(value4.Value); num40++; } return(new SqlOptionalValue(this.ExpandTogether(list12), this.ExpandTogether(list13))); } case SqlNodeType.OuterJoinedValue: { if (exprs[0].SqlType.CanBeColumn) { break; } List <SqlExpression> list14 = new List <SqlExpression>(exprs.Count); int num42 = 0; int num43 = exprs.Count; while (num42 < num43) { if ((exprs[num42] == null) || (exprs[num42].NodeType != SqlNodeType.OuterJoinedValue)) { throw Error.UnionIncompatibleConstruction(); } SqlUnary unary = (SqlUnary)exprs[num42]; list14.Add(unary.Operand); num42++; } return(this.factory.Unary(SqlNodeType.OuterJoinedValue, this.ExpandTogether(list14))); } case SqlNodeType.TypeCase: { SqlTypeCase[] caseArray2 = new SqlTypeCase[exprs.Count]; caseArray2[0] = (SqlTypeCase)exprs[0]; for (int num8 = 1; num8 < caseArray2.Length; num8++) { caseArray2[num8] = (SqlTypeCase)exprs[num8]; } List <SqlExpression> list6 = new List <SqlExpression>(); for (int num9 = 0; num9 < caseArray2.Length; num9++) { list6.Add(caseArray2[num9].Discriminator); } SqlExpression discriminator = this.ExpandTogether(list6); for (int num10 = 0; num10 < caseArray2.Length; num10++) { caseArray2[num10].Discriminator = list6[num10]; } List <SqlTypeCaseWhen> list7 = new List <SqlTypeCaseWhen>(); for (int num11 = 0; num11 < caseArray2[0].Whens.Count; num11++) { List <SqlExpression> list8 = new List <SqlExpression>(); for (int num12 = 0; num12 < caseArray2.Length; num12++) { SqlTypeCaseWhen when2 = caseArray2[num12].Whens[num11]; list8.Add(when2.TypeBinding); } SqlExpression typeBinding = this.ExpandTogether(list8); list7.Add(new SqlTypeCaseWhen(caseArray2[0].Whens[num11].Match, typeBinding)); } return(this.factory.TypeCase(caseArray2[0].ClrType, caseArray2[0].RowType, discriminator, list7, caseArray2[0].SourceExpression)); } case SqlNodeType.Value: { SqlValue value2 = (SqlValue)exprs[0]; for (int num39 = 1; num39 < exprs.Count; num39++) { SqlValue value3 = (SqlValue)exprs[num39]; if (!object.Equals(value3.Value, value2.Value)) { return(this.ExpandIntoExprSet(exprs)); } } return(value2); } } return(this.ExpandIntoExprSet(exprs)); }