public Arguments GetArgument() { var result = new Arguments(); if (TransportMode.HasValue) { result.Add("TransportMode", TransportMode.Value.ToTrafficDeviationInformationString()); } if (!string.IsNullOrEmpty(LineNumber)) { result.Add("LineNumber", LineNumber); } if (SiteId.HasValue) { result.Add("SiteId",SiteId.Value.ToString()); } if (FromDate.HasValue && ToDate.HasValue) { result.Add("FromDate", FromDate.Value.ToString("yyyy-MM-dd")); result.Add("ToDate", ToDate.Value.ToString("yyyy-MM-dd")); } if (FromDate.HasValue ^ ToDate.HasValue) { throw new ArgumentException("if any of the parameters FromDate or ToDate is set then both must be set"); } return result; }
protected virtual IDictionary GetArguments(MethodInfo method, object[] arguments) { var argumentMap = new Arguments(); var parameters = method.GetParameters(); for (int i = 0; i < parameters.Length; i++) { argumentMap.Add(parameters[i].Name, arguments[i]); } return argumentMap; }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var items = value as IEnumerable; var innerValues = new Arguments(); foreach( var item in items ) { innerValues.Add(Util.ToReqlAst(item)); } var makeArray = new MakeArray(innerValues, null); serializer.Serialize(writer, makeArray.Build()); }
public Arguments GetArgument() { var result = new Arguments(); if (!string.IsNullOrEmpty(Ref)) { result.Add("ref", new Argument(Ref) {UrlEncode = false}); } else { throw new ArgumentException("ref can not be null or empty"); } return result; }
public Arguments GetArgument() { var result = new Arguments(); if (!string.IsNullOrEmpty(SearchString)) { result.Add("SearchString", SearchString); } else { throw new ArgumentException("search string can not be null or empty!"); } if (StationsOnly.HasValue) { result.Add("StationsOnly", StationsOnly.Value.ToString().ToLower()); } if (MaxResults.HasValue) { result.Add("MaxResults", MaxResults.Value.ToString()); } return result; }
protected virtual void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args) { args = new Arguments (2); LambdaExpression selector = new LambdaExpression (loc); block.SetParameter (parameter); selector.Block = block; selector.Block.AddStatement (new ContextualReturn (expr)); args.Add (new Argument (selector)); }
protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args) { base.CreateArguments (ec, parameter, ref args); if (element_selector != null) { LambdaExpression lambda = new LambdaExpression (element_selector.Location); element_block.SetParameter (parameter.Clone ()); lambda.Block = element_block; lambda.Block.AddStatement (new ContextualReturn (element_selector)); args.Add (new Argument (lambda)); } }
public override void Emit (EmitContext ec) { if (IsBitwiseBoolean && UserOperator == null) { EmitBitwiseBoolean (ec); return; } if ((Binary.Oper & Binary.Operator.EqualityMask) != 0) { EmitEquality (ec); return; } Label is_null_label = ec.DefineLabel (); Label end_label = ec.DefineLabel (); if (ec.HasSet (BuilderContext.Options.AsyncBody) && Right.ContainsEmitWithAwait ()) { Left = Left.EmitToField (ec); Right = Right.EmitToField (ec); } if (UnwrapLeft != null) { UnwrapLeft.EmitCheck (ec); } // // Don't emit HasValue check when left and right expressions are same // if (UnwrapRight != null && !Binary.Left.Equals (Binary.Right)) { UnwrapRight.EmitCheck (ec); if (UnwrapLeft != null) { ec.Emit (OpCodes.And); } } ec.Emit (OpCodes.Brfalse, is_null_label); if (UserOperator != null) { var args = new Arguments (2); args.Add (new Argument (Left)); args.Add (new Argument (Right)); var call = new CallEmitter (); call.EmitPredefined (ec, UserOperator, args); } else { Binary.EmitOperator (ec, Left, Right); } // // Wrap the result when the operator return type is nullable type // if (type.IsNullableType) ec.Emit (OpCodes.Newobj, NullableInfo.GetConstructor (type)); ec.Emit (OpCodes.Br_S, end_label); ec.MarkLabel (is_null_label); if ((Binary.Oper & Binary.Operator.ComparisonMask) != 0) { ec.EmitInt (0); } else { LiftedNull.Create (type, loc).Emit (ec); } ec.MarkLabel (end_label); }
// // Emits optimized equality or inequality operator when possible // void EmitEquality (EmitContext ec) { // // Either left or right is null // if (UnwrapLeft != null && Binary.Right.IsNull) { // TODO: Optimize for EmitBranchable // // left.HasValue == false // UnwrapLeft.EmitCheck (ec); if (Binary.Oper == Binary.Operator.Equality) { ec.EmitInt (0); ec.Emit (OpCodes.Ceq); } return; } if (UnwrapRight != null && Binary.Left.IsNull) { // // right.HasValue == false // UnwrapRight.EmitCheck (ec); if (Binary.Oper == Binary.Operator.Equality) { ec.EmitInt (0); ec.Emit (OpCodes.Ceq); } return; } Label dissimilar_label = ec.DefineLabel (); Label end_label = ec.DefineLabel (); if (UserOperator != null) { var left = Left; if (UnwrapLeft != null) { UnwrapLeft.EmitCheck (ec); } else { // Keep evaluation order same if (!(Left is VariableReference)) { Left.Emit (ec); var lt = new LocalTemporary (Left.Type); lt.Store (ec); left = lt; } } if (UnwrapRight != null) { UnwrapRight.EmitCheck (ec); if (UnwrapLeft != null) { ec.Emit (OpCodes.Bne_Un, dissimilar_label); Label compare_label = ec.DefineLabel (); UnwrapLeft.EmitCheck (ec); ec.Emit (OpCodes.Brtrue, compare_label); if (Binary.Oper == Binary.Operator.Equality) ec.EmitInt (1); else ec.EmitInt (0); ec.Emit (OpCodes.Br, end_label); ec.MarkLabel (compare_label); } else { ec.Emit (OpCodes.Brfalse, dissimilar_label); } } else { ec.Emit (OpCodes.Brfalse, dissimilar_label); } var args = new Arguments (2); args.Add (new Argument (left)); args.Add (new Argument (Right)); var call = new CallEmitter (); call.EmitPredefined (ec, UserOperator, args); } else { if (ec.HasSet (BuilderContext.Options.AsyncBody) && Binary.Right.ContainsEmitWithAwait ()) { Left = Left.EmitToField (ec); Right = Right.EmitToField (ec); } // // Emit underlying value comparison first. // // For this code: int? a = 1; bool b = a == 1; // // We emit something similar to this. Expressions with side effects have local // variable created by Unwrap expression // // left.GetValueOrDefault () // right // bne.un.s dissimilar_label // left.HasValue // br.s end_label // dissimilar_label: // ldc.i4.0 // end_label: // Left.Emit (ec); Right.Emit (ec); ec.Emit (OpCodes.Bne_Un_S, dissimilar_label); // // Check both left and right expressions for Unwrap call in which // case we need to run get_HasValue() check because the type is // nullable and could have null value // if (UnwrapLeft != null) UnwrapLeft.EmitCheck (ec); if (UnwrapRight != null) UnwrapRight.EmitCheck (ec); if (UnwrapLeft != null && UnwrapRight != null) { if (Binary.Oper == Binary.Operator.Inequality) ec.Emit (OpCodes.Xor); else ec.Emit (OpCodes.Ceq); } else { if (Binary.Oper == Binary.Operator.Inequality) { ec.EmitInt (0); ec.Emit (OpCodes.Ceq); } } } ec.Emit (OpCodes.Br_S, end_label); ec.MarkLabel (dissimilar_label); if (Binary.Oper == Binary.Operator.Inequality) ec.EmitInt (1); else ec.EmitInt (0); ec.MarkLabel (end_label); }
protected override void CreateArguments (ResolveContext ec, out Arguments args) { base.CreateArguments (ec, out args); if (element_selector != null) { LambdaExpression lambda = new LambdaExpression (element_selector.Location); lambda.Block = element_block; lambda.Block.AddStatement (new ContextualReturn (element_selector)); args.Add (new Argument (lambda)); } }
public override Expression CreateExpressionTree (ResolveContext rc) { if (UserOperator != null) { Arguments args = new Arguments (2); args.Add (new Argument (Binary.Left)); args.Add (new Argument (Binary.Right)); var method = new UserOperatorCall (UserOperator, args, Binary.CreateExpressionTree, loc); return method.CreateExpressionTree (rc); } return Binary.CreateExpressionTree (rc); }
public override Expression CreateExpressionTree (ResolveContext ec) { if (left is NullLiteral) ec.Report.Error (845, loc, "An expression tree cannot contain a coalescing operator with null left side"); UserCast uc = left as UserCast; Expression conversion = null; if (uc != null) { left = uc.Source; Arguments c_args = new Arguments (2); c_args.Add (new Argument (uc.CreateExpressionTree (ec))); c_args.Add (new Argument (left.CreateExpressionTree (ec))); conversion = CreateExpressionFactoryCall (ec, "Lambda", c_args); } Arguments args = new Arguments (3); args.Add (new Argument (left.CreateExpressionTree (ec))); args.Add (new Argument (right.CreateExpressionTree (ec))); if (conversion != null) args.Add (new Argument (conversion)); return CreateExpressionFactoryCall (ec, "Coalesce", args); }
protected override void CreateArguments (ResolveContext ec, out Arguments args) { args = new Arguments (4); args.Add (new Argument (expr)); LambdaExpression lambda = new LambdaExpression (outer_selector.StartLocation); lambda.Block = outer_selector; args.Add (new Argument (lambda)); lambda = new LambdaExpression (inner_selector.StartLocation); lambda.Block = inner_selector; args.Add (new Argument (lambda)); Expression result_selector_expr; LocatedToken into_variable = GetIntoVariable (); // // When select follows use is as result selector // if (next is Select) { result_selector_expr = next.expr; next = next.next; } else { result_selector_expr = CreateRangeVariableType (block, ec.MemberContext, into_variable, new SimpleName (into_variable.Value, into_variable.Location)); } LambdaExpression result_selector = new LambdaExpression (lt.Location); result_selector.Block = new QueryBlock (ec.Compiler, block.Parent, block.Parameters, into_variable, block.StartLocation); result_selector.Block.AddStatement (new ContextualReturn (result_selector_expr)); args.Add (new Argument (result_selector)); }
protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args) { args = new Arguments (4); if (IdentifierType != null) expr = CreateCastExpression (expr); args.Add (new Argument (expr)); outer_selector.SetParameter (parameter.Clone ()); var lambda = new LambdaExpression (outer_selector.StartLocation); lambda.Block = outer_selector; args.Add (new Argument (lambda)); inner_selector.SetParameter (new ImplicitLambdaParameter (identifier.Name, identifier.Location)); lambda = new LambdaExpression (inner_selector.StartLocation); lambda.Block = inner_selector; args.Add (new Argument (lambda)); base.CreateArguments (ec, parameter, ref args); }
public Arguments GetArgument() { var result = new Arguments(); if (Lang.HasValue) { result.Add("lang", Lang.Value.ToTripLanguageString()); } if (DateTime.HasValue) { result.Add("date", DateTime.Value.Date.ToString("yyyy-MM-dd")); result.Add("time", DateTime.Value.ToString("HH:mm")); } if (SearchForArrival.HasValue) { result.Add("searchForArrival", SearchForArrival.Value ? "1" : "0"); } if (NumberOfChanges.HasValue) { result.Add("numChg", NumberOfChanges.Value.ToString()); } if (MinimumChangeTime.HasValue) { result.Add("minChgTime", MinimumChangeTime.Value.ToString()); } if (!string.IsNullOrEmpty(OriginId)) { result.Add("originId", OriginId); } foreach (var arg in Origin.GetArgument()) { result.Add(arg.Key, arg.Value); } foreach (var arg in Destination.GetArgument()) { result.Add(arg.Key, arg.Value); } if (!string.IsNullOrEmpty(DestId)) { result.Add("destId", DestId); } if (ViaIds.Any()) { var sb = new StringBuilder(); var counter = 0; var length = ViaIds.Length; foreach (var viaId in ViaIds) { sb.Append(viaId); if (counter + 1 < length) { sb.Append(","); } counter++; } result.Add("viaId", sb.ToString()); } if (ViaStopOver.HasValue) { result.Add("viaStopOver", ViaStopOver.Value.ToString()); } if (Unsharp.HasValue) { result.Add("unsharp", Unsharp.Value ? "1" : "0"); } if (SearchFirstLastTrip.HasValue) { result.Add("searchFirstLastTrip", SearchFirstLastTrip.Value ? "first" : "last"); } if (MaxWalkDist.HasValue) { result.Add("maxWalkDist", MaxWalkDist.Value.ToString()); } if (UseTrain.HasValue) { result.Add("useTrain", UseTrain.Value ? "1" : "0"); } if (UseMetro.HasValue) { result.Add("useMetro", UseTrain.Value ? "1" : "0"); } if (UseTram.HasValue) { result.Add("useTram", UseTram.Value ? "1" : "0"); } if (UseBus.HasValue) { result.Add("useBus", UseTram.Value ? "1" : "0"); } if (UseFerry.HasValue) { result.Add("useFerry", UseTram.Value ? "1" : "0"); } if (UseShip.HasValue) { result.Add("useShip", UseShip.Value ? "1" : "0"); } if (LineInc.Any()) { var sb = new StringBuilder(); var counter = 0; var length = LineInc.Length; foreach (var line in LineInc) { sb.Append(line); if (counter + 1 < length) { sb.Append(","); } counter++; } result.Add("lineInc", sb.ToString()); } if (LineExc.Any()) { var sb = new StringBuilder(); var counter = 0; var length = LineExc.Length; foreach (var line in LineExc) { sb.Append(line); if (counter + 1 < length) { sb.Append(","); } counter++; } result.Add("lineExc", sb.ToString()); } if (NumTrips.HasValue) { result.Add("numTrips", NumTrips.Value.ToString()); } if (Encoding != null) { result.Add("encoding", Encoding.WebName); } return result; }
protected override void CreateArguments (ResolveContext ec, out Arguments args) { base.CreateArguments (ec, out args); Expression result_selector_expr; // // When select follow use is as result selector // if (next is Select) { result_selector_expr = next.expr; next = next.next; } else { result_selector_expr = CreateRangeVariableType (block, ec.MemberContext, lt, new SimpleName (lt.Value, lt.Location)); } LambdaExpression result_selector = new LambdaExpression (lt.Location); result_selector.Block = new QueryBlock (ec.Compiler, block.Parent, block.Parameters, lt, block.StartLocation); result_selector.Block.AddStatement (new ContextualReturn (result_selector_expr)); args.Add (new Argument (result_selector)); }
private static ReqlAst ToReqlAst(object val, int remainingDepth, Func<object, ReqlAst> hook = null ) { if( remainingDepth <= 0 ) { throw new ReqlDriverCompileError("Recursion limit reached converting to ReqlAst"); } if( hook != null ) { var converted = hook(val); if( !ReferenceEquals(converted, null) ) { return converted; } } var ast = val as ReqlAst; if( !ReferenceEquals(ast, null) ) { return ast; } var token = val as JToken; if( token != null ) { return new Poco(token); } var lst = val as IList; if( lst != null ) { Arguments innerValues = new Arguments(); foreach( object innerValue in lst ) { innerValues.Add(ToReqlAst(innerValue, remainingDepth - 1)); } return new MakeArray(innerValues, null); } var dict = val as IDictionary; if( dict != null ) { var obj = new Dictionary<string, ReqlAst>(); foreach( var keyObj in dict.Keys ) { var key = keyObj as string; if( key == null ) { throw new ReqlDriverCompileError("Object keys can only be strings"); } obj[key] = ToReqlAst(dict[keyObj]); } return MakeObj.fromMap(obj); } var del = val as Delegate; if( del != null ) { return Func.FromLambda(del); } var dt = val as DateTime?; if (dt != null) { return new Poco(dt); } var dto = val as DateTimeOffset?; if (dto != null) { return new Poco(dto); } var @int = val as int?; if( @int != null ) { return new Datum(@int); } if( IsNumber(val) ) { return new Datum(val); } var @bool = val as bool?; if( @bool != null ) { return new Datum(@bool); } var str = val as string; if( str != null ) { return new Datum(str); } if( val == null ) { return new Datum(null); } return new Poco(val); }
//TODO: don't use "is" for performance private static ReqlAst ToReqlAst(object val, int remainingDepth) { if (val is ReqlAst) { return (ReqlAst) val; } if (val is IList) { Arguments innerValues = new Arguments(); foreach (object innerValue in (IList) val) { innerValues.Add(ToReqlAst(innerValue, remainingDepth - 1)); } return new MakeArray(innerValues, null); } if (val is IDictionary) { var obj = new Dictionary<string, ReqlAst>(); foreach (var entry in val as IDictionary<string, object>) { if (!(entry.Key is string)) { throw new ReqlError("Object key can only be strings"); } obj[(string) entry.Key] = ToReqlAst(entry.Value); } return MakeObj.FromMap(obj); } if (val is ReqlLambda) { return Func.FromLambda((ReqlLambda)val); } if (val is DateTime) { var dt = (DateTime)val; var isoStr = dt.ToUniversalTime().ToString("o"); return Iso8601.FromString(isoStr); } if (val is int?) { return new Datum((int?) val); } if (IsNumber(val)) { return new Datum(val); } if (val is bool?) { return new Datum((bool?) val); } if (val is string) { return new Datum((string) val); } if( val == null ) { return new Datum(null); } throw new ReqlDriverError($"Can't convert {val} to a ReqlAst"); }
protected override void CreateArguments (ResolveContext ec, Parameter parameter, ref Arguments args) { if (args == null) { if (IdentifierType != null) expr = CreateCastExpression (expr); base.CreateArguments (ec, parameter, ref args); } Expression result_selector_expr; QueryBlock result_block; var target = GetIntoVariable (); var target_param = new ImplicitLambdaParameter (target.Name, target.Location); // // When select follows use it as a result selector // if (next is Select) { result_selector_expr = next.Expr; result_block = next.block; result_block.SetParameters (parameter, target_param); next = next.next; } else { result_selector_expr = CreateRangeVariableType (ec, parameter, target, new SimpleName (target.Name, target.Location)); result_block = new QueryBlock (ec.Compiler, block.Parent, block.StartLocation); result_block.SetParameters (parameter, target_param); } LambdaExpression result_selector = new LambdaExpression (Location); result_selector.Block = result_block; result_selector.Block.AddStatement (new ContextualReturn (result_selector_expr)); args.Add (new Argument (result_selector)); }
private static ReqlAst ToReqlAst(object val, int remainingDepth) { if( remainingDepth <= 0 ) { throw new ReqlDriverCompileError("Recursion limit reached converting to ReqlAst"); } var ast = val as ReqlAst; if( ast != null ) { return ast; } var lst = val as IList; if( lst != null ) { Arguments innerValues = new Arguments(); foreach( object innerValue in lst ) { innerValues.Add(ToReqlAst(innerValue, remainingDepth - 1)); } return new MakeArray(innerValues, null); } var dict = val as IDictionary; if( dict != null ) { var obj = new Dictionary<string, ReqlAst>(); foreach( var keyObj in dict.Keys ) { var key = keyObj as string; if( key == null ) { throw new ReqlDriverCompileError("Object keys can only be strings"); } obj[key] = ToReqlAst(dict[keyObj]); } return MakeObj.fromMap(obj); } var del = val as Delegate; if( del != null ) { return Func.FromLambda(del); } if( val is DateTime ) { var dt = (DateTime)val; var isoStr = dt.ToString("o"); return Iso8601.FromString(isoStr); } if( val is DateTimeOffset ) { var dt = (DateTimeOffset)val; var isoStr = dt.ToString("o"); return Iso8601.FromString(isoStr); } var @int = val as int?; if( @int != null ) { return new Datum(@int); } if( IsNumber(val) ) { return new Datum(val); } var @bool = val as bool?; if( @bool != null ) { return new Datum(@bool); } var str = val as string; if( str != null ) { return new Datum(str); } if( val == null ) { return new Datum(null); } return new Poco(val); }
/// <summary> /// Deserializes arguments from an XML file. /// </summary> /// <param name="reader">XMLReader where the arguments are.</param> /// <returns>Arguments.</returns> public static Arguments Deserialize(XmlReader reader) { Arguments lResult = null; if (reader.IsStartElement(DTD.Request.ServiceRequest.TagArguments)) { lResult = new Arguments(); if (!reader.IsEmptyElement) { reader.ReadStartElement(); do { if (reader.IsStartElement(DTD.Request.ServiceRequest.Arguments.TagArgument)) { lResult.Add(XMLArgumentSerializer.Deserialize(reader.ReadSubtree())); } } while (reader.Read()); } else { reader.Skip(); } } else { throw new ArgumentException("Xml Reader don't have the " + DTD.Request.ServiceRequest.TagArguments + "in Start Element.", "XmlReader reader"); } return lResult; }
public override Expression CreateExpressionTree (ResolveContext ec) { Arguments args = new Arguments (2); args.Add (new Argument (this)); args.Add (new Argument (new TypeOf (new TypeExpression (type, loc), loc))); return CreateExpressionFactoryCall (ec, "Constant", args); }