MakeBinary() public static method

Creates a BinaryExpression, given the left and right operands, by calling an appropriate factory method.
public static MakeBinary ( ExpressionType binaryType, Expression left, Expression right ) : BinaryExpression
binaryType ExpressionType The ExpressionType that specifies the type of binary operation.
left Expression An Expression that represents the left operand.
right Expression An Expression that represents the right operand.
return BinaryExpression
        private LambdaExpression fromEnumerableLambda(Type from)
        {
            var input = Ex.Parameter(from, "input");
            var eType = from.GetTypeInfo().ImplementedInterfaces
                        .Where(i => i.GenericTypeArguments.Length == 1 && i.GetGenericTypeDefinition() == typeof(IEnumerable <>))
                        .Select(i => i.GenericTypeArguments[0]).SingleOrDefault()
                        ?? from.GetTypeInfo().GenericTypeArguments[0];
            var res    = Ex.Parameter(typeof(string), "res");
            var result = Ex.Block(new[] { res },
                                  Ex.Assign(res, Ex.Call((from mi in typeof(string).GetTypeInfo().GetDeclaredMethods(nameof(string.Join))
                                                          where mi.GetGenericArguments().Length == 1
                                                          let par = mi.GetParameters()
                                                                    where par.Length == 2 &&
                                                                    par[0].ParameterType == typeof(string) &&
                                                                    par[1].ParameterType == typeof(IEnumerable <>).MakeGenericType(mi.GetGenericArguments()[0])
                                                                    select mi).Single().MakeGenericMethod(eType),
                                                         Ex.Constant(Separators[0].ToString()), input)),
                                  Ex.Condition(Ex.MakeBinary(Et.Equal, Ex.Property(res, nameof(string.Length)), Ex.Constant(0)),
                                               NoResult(typeof(string)),
                                               Result(typeof(string), res)));

            var block = Ex.Condition(Ex.MakeBinary(Et.Equal, input, Ex.Default(from)),
                                     NoResult(typeof(string)),
                                     result);
            var lambda = Ex.Lambda(block, input);

            return(lambda);
        }
Ejemplo n.º 2
0
        // Pseudocode:
        //string input =>
        //{
        //    R result = 0;
        //    for (int i = input.Length - 1; i >= 0; i--)
        //    {
        //        result <<= 6;
        //        var m = _invMap[input[i]];
        //        if (m == 0xff)
        //            return default(ConversionResult<R>);
        //        result += m;
        //    }
        //    return new ConversionResult<R>(result);
        //}
        private LambdaExpression fromLambda(Type to)
        {
            var stringthis = typeof(string).GetTypeInfo().DeclaredProperties.First(p => p.GetIndexParameters().Length == 1 && p.GetIndexParameters()[0].ParameterType == typeof(int));
            var input      = Ex.Parameter(typeof(string), "input");
            var result     = Ex.Parameter(to, "result");
            var i          = Ex.Parameter(typeof(int), "i");
            var m          = Ex.Parameter(typeof(byte), "m");
            var loopstart  = Ex.Label("loopstart");
            var end        = Ex.Label(typeof(ConversionResult <>).MakeGenericType(to), "end");
            var loop       = Ex.Block(
                Ex.Label(loopstart),
                Ex.IfThen(Ex.MakeBinary(ExpressionType.LessThan, i, Ex.Constant(0)),
                          Ex.Goto(end, Result(to, result))),
                Ex.LeftShiftAssign(result, Ex.Constant(6)),
                Ex.Assign(m, Ex.ArrayIndex(Ex.Constant(_invMap), Ex.Convert(Ex.MakeIndex(input, stringthis, new[] { i }), typeof(int)))),
                Ex.IfThen(Ex.MakeBinary(ExpressionType.Equal, m, Ex.Constant((byte)0xff)),
                          Ex.Goto(end, NoResult(to))),
                Ex.AddAssign(result, Ex.Convert(m, result.Type)),
                Ex.PostDecrementAssign(i),
                Ex.Goto(loopstart));
            var block = Ex.Block(new[] { result, i, m },
                                 Ex.Assign(result, Ex.Convert(Ex.Constant(0), to)),
                                 Ex.Assign(i, Ex.MakeBinary(ExpressionType.Subtract, Ex.Property(input, nameof(string.Length)), Ex.Constant(1))),
                                 loop,
                                 Ex.Label(end, NoResult(to)));

            return(Ex.Lambda(block, input));
        }
        public LambdaExpression CreateLambda(Type from, Type to)
        {
            var input    = Ex.Parameter(from, "input");
            var fromInfo = infos[from];
            var toInfo   = infos[to];

            if (fromInfo <= toInfo) // Can make use of an implicit conversion
            {
                var block  = Result(to, Ex.Convert(input, to));
                var lambda = Ex.Lambda(block, input);
                return(lambda);
            }
            else // Cannot make use of an implicit conversion, bounds must be checked. Precision might be lost.
            {
                var block = Ex.Condition(
                    Ex.MakeBinary(Et.AndAlso,
                                  Ex.MakeBinary(Et.GreaterThanOrEqual,
                                                input,
                                                Ex.Convert(Ex.Constant(toInfo.MinValue), from)),
                                  Ex.MakeBinary(Et.LessThanOrEqual,
                                                input,
                                                Ex.Convert(Ex.Constant(toInfo.MaxValue), from))),
                    Result(to, Ex.Convert(input, to)),
                    NoResult(to));
                var lambda = Ex.Lambda(block, input);
                return(lambda);
            }
        }
        public LambdaExpression CreateLambda(Type from, Type to)
        {
            var toParameters = to.GetTypeInfo().GenericTypeArguments;
            var tupa         = toParameters.Length;
            var input        = Ex.Parameter(from, "input");
            var converters   = toParameters.Select(p => Ref.GetLambda(typeof(string), p)).ToArray();
            var res          = toParameters.Select(p => Ex.Parameter(typeof(ConversionResult <>).MakeGenericType(p))).ToArray();
            var end          = Ex.Label(typeof(ConversionResult <>).MakeGenericType(to), "end");
            var indexer      = typeof(string[]).GetTypeInfo().GetDeclaredProperty("Item");

            var split      = Ex.Parameter(typeof(string[]), "split");
            var conversion = Ex.Block(converters.Select((c, i) =>
                                                        Ex.Block(
                                                            Ex.Assign(res[i],
                                                                      c.ApplyTo(Ex.MakeIndex(split, indexer, new[] { Ex.MakeBinary(Et.Add, Ex.Constant(i), Ex.MakeBinary(Et.Subtract, Ex.Property(split, nameof(Array.Length)), Ex.Constant(tupa))) }))),
                                                            Ex.IfThen(Ex.Not(Ex.Property(res[i], nameof(IConversionResult.IsSuccessful))),
                                                                      Ex.Goto(end, NoResult(to))))));
            var block = Ex.Block(new[] { split },
                                 Ex.Assign(split, Ex.Call(input, nameof(string.Split), Type.EmptyTypes, _separator)),
                                 Ex.Condition(Ex.MakeBinary(Et.LessThan, Ex.Property(split, nameof(Array.Length)), Ex.Constant(tupa)),
                                              NoResult(to),
                                              Ex.Block(res,
                                                       Ex.IfThen(Ex.MakeBinary(Et.GreaterThan, Ex.Property(split, nameof(Array.Length)), Ex.Constant(tupa)),
                                                                 Ex.Assign(Ex.ArrayAccess(split, Ex.MakeBinary(Et.Subtract, Ex.Property(split, nameof(Array.Length)), Ex.Constant(tupa))),
                                                                           Ex.Call(typeof(string), nameof(string.Join), Type.EmptyTypes, _separatorString,
                                                                                   Ex.Call(typeof(Enumerable), nameof(Enumerable.Take), new[] { typeof(string) }, split,
                                                                                           Ex.MakeBinary(Et.Add, Ex.Constant(1), Ex.MakeBinary(Et.Subtract, Ex.Property(split, nameof(Array.Length)), Ex.Constant(tupa))))))),
                                                       conversion,
                                                       Ex.Label(end, Result(to, Ex.Call(Creator(to), res.Select(r => Ex.Property(r, nameof(IConversionResult.Result)))))))));
            var lambda = Ex.Lambda(block, input);

            return(lambda);
        }
Ejemplo n.º 5
0
        private Exp MakeBinary(CompilerState state, ExpressionType op, Exp lhs, Exp rhs)
        {
            if (state == null)
            {
                throw new Exception();
            }
            if (lhs == null)
            {
                throw new Exception();
            }
            if (rhs == null)
            {
                throw new Exception();
            }

            Transform(ref lhs, ref rhs);

            if (op == ExpressionType.Divide)
            {
                CheckIfZero(state, rhs);
            }

            switch (op)
            {
            case ExpressionType.And:
            case ExpressionType.Or:
            case ExpressionType.ExclusiveOr:
                lhs = ToBoolean(lhs);
                rhs = ToBoolean(rhs);
                break;
            }

            return(Exp.MakeBinary(op, lhs, rhs));
        }
Ejemplo n.º 6
0
        public LambdaExpression CreateLambda(Type from, Type to)
        {
            var fromParameters = from.GetTypeInfo().GenericTypeArguments;
            var toParameters   = to.GetTypeInfo().GenericTypeArguments;

            var converters = fromParameters
                             .Zip(toParameters, (f, t) => Ref.GetLambda(f, t))
                             .ToArray();
            var input = Ex.Parameter(from, "input");

            var res = toParameters.Select(t => Ex.Parameter(typeof(ConversionResult <>).MakeGenericType(t))).ToArray();

            var conversion = res.Select((r, i) =>
                                        Ex.Assign(res[i], converters[i].ApplyTo(Ex.PropertyOrField(input, $"Item{i + 1}")))).ToArray();
            var conversionSuccesful = Enumerable.Aggregate(res, (Ex)Ex.Constant(true),
                                                           (c, p) => Ex.MakeBinary(Et.AndAlso, c, Ex.Property(p, nameof(IConversionResult.IsSuccessful))));

            var block = Ex.Block(res,
                                 Ex.Block(conversion),
                                 Ex.Condition(conversionSuccesful,
                                              Result(to,
                                                     Ex.Call(Creator(to), Enumerable.Select(res, p => Ex.Property(p, nameof(IConversionResult.Result))))),
                                              NoResult(to)));
            var lambda = Ex.Lambda(block, input);

            return(lambda);
        }
Ejemplo n.º 7
0
        public void Regular(Linq.ExpressionType binaryType, Type leftType = null, Type rightType = null)
        {
            leftType ??= typeof(int);
            rightType ??= leftType;

            var expected = LinqExpression.MakeBinary(
                binaryType,
                LinqExpression.Parameter(
                    leftType),
                LinqExpression.Parameter(
                    rightType));

            var actual = $@"
@prefix : <http://example.com/> .
@prefix xt: <http://example.com/ExpressionTypes/> .

:s
    :binaryExpressionType xt:{binaryType} ;
    :binaryLeft [
        :parameterType [
            :typeName ""{leftType}"" ;
        ]
    ] ;
    :binaryRight [
        :parameterType [
            :typeName ""{rightType}"" ;
        ] ;
    ] ;
.
";

            ShouldBe(actual, expected);
        }
Ejemplo n.º 8
0
        private LambdaExpression toDictLambda(Type from, Type to)
        {
            var valueType = recordCreator.GetValueType(to);
            var recType   = typeof(IRecord <>).MakeGenericType(valueType);
            var set       = recType.GetTypeInfo().GetDeclaredMethod(nameof(IRecord <object> .SetValue));

            var input      = Ex.Parameter(from, "input");
            var tmp        = Ex.Parameter(typeof(ConversionResult <>).MakeGenericType(valueType), "tmp");
            var res        = Ex.Parameter(typeof(IDictionary <,>).MakeGenericType(typeof(string), valueType), "res");
            var rec        = Ex.Parameter(recType, "rec");
            var getters    = GetReadablePropertiesForType(from);
            var converters = getters.Select(g => Ref.GetLambda(g.PropertyType, valueType));

            var end   = Ex.Label(typeof(ConversionResult <>).MakeGenericType(to));
            var block = Ex.Block(new[] { tmp, res, rec },
                                 Ex.Assign(res, Ex.New(GetParameterlessConstructor(to))),
                                 Ex.Assign(rec, recordCreator.Creator(to).ApplyTo(res)),
                                 Ex.IfThen(Ex.MakeBinary(ExpressionType.Equal, rec, Ex.Default(rec.Type)), Ex.Goto(end, NoResult(to))),
                                 Ex.Block(getters.Zip(converters, (g, c) => new { g, c })
                                          .Select(x =>
                                                  Ex.Block(
                                                      Ex.Assign(tmp, x.c.ApplyTo(Ex.Property(input, x.g))),
                                                      Ex.IfThenElse(Ex.Property(tmp, nameof(IConversionResult.IsSuccessful)),
                                                                    Ex.Call(rec, set, Ex.Constant(x.g.Name), Ex.Property(tmp, nameof(IConversionResult.Result))),
                                                                    Ex.Goto(end, NoResult(to)))))),
                                 Ex.Label(end, Result(to, Ex.Convert(res, to))));

            return(Ex.Lambda(block, input));
        }
 private static Ex conditional(Type from, Ex input, Ex result)
 {
     return(Ex.Condition(
                Ex.MakeBinary(Et.OrElse,
                              Ex.MakeBinary(Et.Equal, input, Ex.Default(from)),
                              Ex.MakeBinary(Et.Equal, Ex.Property(input, nameof(Array.Length)), Ex.Constant(0))),
                NoResult(typeof(string)),
                Result(typeof(string), result)));
 }
        /// <inheritdoc/>
        protected override IEnumerable <Act> Query(Expression <Func <Act, bool> > query, Guid queryId, int offset, int count, out int totalResults)
        {
            var typeReference = Expression.MakeBinary(ExpressionType.Equal, Expression.Convert(Expression.MakeMemberAccess(query.Parameters[0], typeof(Act).GetProperty(nameof(Act.ClassConceptKey))), typeof(Guid)), Expression.Constant(ActClassKeys.Condition));

            var anyRef = this.CreateConceptSetFilter(ConceptSetKeys.AdverseEventActs, query.Parameters[0]);

            query = Expression.Lambda <Func <Act, bool> >(Expression.AndAlso(Expression.AndAlso(query.Body, anyRef), typeReference), query.Parameters);

            return(base.Query(query, queryId, offset, count, out totalResults));
        }
        public LambdaExpression CreateLambda(Type from, Type to)
        {
            var input = Ex.Parameter(from, "input");
            var ut    = Enum.GetUnderlyingType(to);

            if (from == ut)
            {
                if (to.GetTypeInfo().GetCustomAttributes <FlagsAttribute>().Any())
                {
                    var vals  = Enum.GetValues(to).OfType <object>().Select(x => Convert.ToInt64(x));
                    var mask  = vals.Aggregate(0L, (x, y) => x | y);
                    var block = Ex.Condition(
                        Ex.MakeBinary(Et.Equal,
                                      Ex.MakeBinary(Et.And, input, Ex.Constant(helper.DoGeneralConversion(mask, ut).Result, ut)),
                                      input),
                        Result(to, Ex.Convert(input, to)),
                        NoResult(to));
                    var lambda = Ex.Lambda(block, input);
                    return(lambda);
                }
                else
                {
                    var vals  = Enum.GetValues(to).OfType <object>().Select(x => Convert.ToInt64(x));
                    var min   = vals.Min();
                    var max   = vals.Max();
                    var block = Ex.Condition(
                        Ex.MakeBinary(Et.AndAlso,
                                      Ex.MakeBinary(Et.GreaterThanOrEqual, input, Ex.Constant(helper.DoGeneralConversion(min, ut).Result, ut)),
                                      Ex.MakeBinary(Et.LessThanOrEqual, input, Ex.Constant(helper.DoGeneralConversion(max, ut).Result, ut))),
                        Result(to, Ex.Convert(input, to)),
                        NoResult(to));
                    var lambda = Ex.Lambda(block, input);
                    return(lambda);
                }
            }
            else
            {
                var res   = Ex.Parameter(typeof(ConversionResult <>).MakeGenericType(ut), "res");
                var c1    = Ref.GetLambda(from, ut);
                var c2    = Ref.GetLambda(ut, to);
                var block = Ex.Block(new[] { res },
                                     Ex.Assign(res, c1.ApplyTo(input)),
                                     Ex.Condition(Ex.Property(res, nameof(IConversionResult.IsSuccessful)),
                                                  c2.ApplyTo(Ex.Property(res, nameof(IConversionResult.Result))),
                                                  NoResult(to)));
                var lambda = Ex.Lambda(block, input);
                return(lambda);
            }
        }
        private LambdaExpression fromStringLambda(Type to)
        {
            var input     = Ex.Parameter(typeof(string), "input");
            var split     = Ex.Parameter(typeof(string[]), "split");
            var converter = Ref.GetLambda(typeof(string[]), to);
            var block     = Ex.Condition(Ex.MakeBinary(Et.Equal, input, Ex.Default(typeof(string))),
                                         NoResult(to),
                                         Ex.Block(new[] { split },
                                                  Ex.Assign(split, Ex.Call(input, nameof(string.Split), Type.EmptyTypes, Ex.Constant(Separators))),
                                                  Ex.Condition(Ex.MakeBinary(Et.Equal, Ex.Property(split, nameof(Array.Length)), Ex.Constant(1)),
                                                               NoResult(to),
                                                               converter.ApplyTo(split))));
            var lambda = Ex.Lambda(block, input);

            return(lambda);
        }
        /// <summary>
        /// Query for substance administrations that aren't immunizations
        /// </summary>
        /// <param name="query">The query.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="count">The count.</param>
        /// <param name="totalResults">The total results.</param>
        /// <param name="queryId">The unique query state identifier</param>
        /// <returns>Returns the list of models which match the given parameters.</returns>
        protected override IEnumerable <SubstanceAdministration> Query(Expression <Func <SubstanceAdministration, bool> > query, Guid queryId, int offset, int count, out int totalResults)
        {
            var drugTherapy = Guid.Parse("7D84A057-1FCC-4054-A51F-B77D230FC6D1");

            var obsoletionReference = Expression.MakeBinary(ExpressionType.Equal, Expression.Convert(Expression.MakeMemberAccess(query.Parameters[0], typeof(SubstanceAdministration).GetProperty(nameof(SubstanceAdministration.StatusConceptKey))), typeof(Guid)), Expression.Constant(StatusKeys.Completed));
            var typeReference       = Expression.MakeBinary(ExpressionType.Equal, Expression.Convert(Expression.MakeMemberAccess(query.Parameters[0], typeof(SubstanceAdministration).GetProperty(nameof(SubstanceAdministration.TypeConceptKey))), typeof(Guid)), Expression.Constant(drugTherapy));

            query = Expression.Lambda <Func <SubstanceAdministration, bool> >(Expression.AndAlso(Expression.AndAlso(obsoletionReference, query.Body), typeReference), query.Parameters);

            if (queryId == Guid.Empty)
            {
                return(this.m_repository.Find(query, offset, count, out totalResults));
            }

            return((this.m_repository as IPersistableQueryRepositoryService <SubstanceAdministration>).Find(query, offset, count, out totalResults, queryId));
        }
Ejemplo n.º 14
0
 public LambdaExpression CreateLambda(Type from, Type to)
 {
     if (from == typeof(bool))
     {
         var input = Ex.Parameter(typeof(bool), "input");
         if (to == typeof(string))
         {
             return(Ex.Lambda(Result(to, Ex.Call(input, nameof(bool.ToString), Type.EmptyTypes)), input));
         }
         else
         {
             return(Ex.Lambda(Result(to, Ex.Condition(input, Ex.Constant(Convert.ChangeType(1, to), to), Ex.Constant(Convert.ChangeType(0, to), to))), input));
         }
     }
     else // to == typeof(bool)
     {
         var input = Ex.Parameter(from, "input");
         if (from == typeof(string))
         {
             var i    = Ex.Parameter(typeof(int), "i");
             var body = Ex.Block(new[] { i },
                                 Ex.Condition(
                                     Ex.Call(typeof(string), nameof(string.Equals), Type.EmptyTypes,
                                             input,
                                             Ex.Constant("true"),
                                             Ex.Constant(StringComparison.OrdinalIgnoreCase)),
                                     Result(to, Ex.Constant(true)),
                                     Ex.Condition(
                                         Ex.Call(typeof(string), nameof(string.Equals), Type.EmptyTypes,
                                                 input,
                                                 Ex.Constant("false"),
                                                 Ex.Constant(StringComparison.OrdinalIgnoreCase)),
                                         Result(to, Ex.Constant(false)),
                                         Ex.Condition(Ex.Call(typeof(int), nameof(int.TryParse), Type.EmptyTypes, input, i),
                                                      Result(to, Ex.MakeBinary(ExpressionType.NotEqual, i, Ex.Constant(0))),
                                                      NoResult(to)))));
             return(Ex.Lambda(body, input));
         }
         else
         {
             return(Ex.Lambda(Result(to,
                                     Ex.MakeBinary(ExpressionType.NotEqual, input, Ex.Constant(Convert.ChangeType(0, from), from))), input));
         }
     }
 }
Ejemplo n.º 15
0
        private LambdaExpression constructionLambda(Type from, Type to)
        {
            var valueType = recordCreator.GetValueType(from);
            var recType   = typeof(IRecord <>).MakeGenericType(valueType);
            var tryGet    = recType.GetTypeInfo().GetDeclaredMethod(nameof(IRecord <object> .TryGetValue));

            var input = Ex.Parameter(from, "input");
            var rec   = Ex.Parameter(recType, "rec");
            var ctor  = GetConstructorForType(to);
            var tmp   = Ex.Parameter(valueType, "tmp");
            var pars  = ctor.GetParameters().Select((p, i) => new
            {
                Converter = Ref.GetLambda(valueType, p.ParameterType),
                Var       = Ex.Parameter(typeof(ConversionResult <>).MakeGenericType(p.ParameterType), p.Name),
                Type      = p.ParameterType,
                Optional  = p.GetCustomAttributes <OptionalAttribute>().Any(),
                Default   = p.HasDefaultValue ? p.DefaultValue : p.ParameterType.GetTypeInfo().IsValueType ? Activator.CreateInstance(p.ParameterType) : null
            }).ToArray();
            var end   = Ex.Label(typeof(ConversionResult <>).MakeGenericType(to), "end");
            var block = Ex.Block(new[] { rec }.Concat(pars.Select(x => x.Var)),
                                 Ex.Assign(rec, recordCreator.Creator(from).ApplyTo(input)),
                                 Ex.Block(new[] { tmp }, pars
                                          .Select(x =>
                                                  x.Optional
                        ? Ex.Block(
                                                      Ex.IfThenElse(
                                                          Ex.MakeBinary(ExpressionType.OrElse,
                                                                        Ex.Call(rec, tryGet, Ex.Constant(x.Var.Name), tmp),
                                                                        Ex.Call(rec, tryGet, Ex.Constant(ToPascalCase(x.Var.Name)), tmp)),
                                                          Ex.Block(
                                                              Ex.Assign(x.Var, x.Converter.ApplyTo(tmp)),
                                                              Ex.IfThen(Ex.Not(Ex.Property(x.Var, nameof(IConversionResult.IsSuccessful))),
                                                                        Ex.Goto(end, NoResult(to)))),
                                                          Ex.Assign(x.Var, Result(x.Type, Ex.Constant(x.Default, x.Type)))))
                        : Ex.Block(
                                                      Ex.IfThen(Ex.Not(Ex.Call(rec, tryGet, Ex.Constant(x.Var.Name), tmp)),
                                                                Ex.IfThen(Ex.Not(Ex.Call(rec, tryGet, Ex.Constant(ToPascalCase(x.Var.Name)), tmp)),
                                                                          Ex.Goto(end, NoResult(to)))),
                                                      Ex.Assign(x.Var, x.Converter.ApplyTo(tmp)),
                                                      Ex.IfThen(Ex.Not(Ex.Property(x.Var, nameof(IConversionResult.IsSuccessful))),
                                                                Ex.Goto(end, NoResult(to)))))),
                                 Ex.Label(end, Result(to, Ex.New(ctor, pars.Select(p => Ex.Property(p.Var, nameof(IConversionResult.Result)))))));

            return(Ex.Lambda(block, input));
        }
Ejemplo n.º 16
0
        // Pseudocode:
        //I input =>
        //{
        //  var i = (UI)input;
        //  var result = new char[base64sizeof(UI)];
        //  for (int j = 0; j == 0 || i > 0; j++)
        //  {
        //      result[j] = _mapChar[i & 0x3f];
        //      i >>= 6;
        //  }
        //}
        private LambdaExpression toLambda(Type from)
        {
            var input     = Ex.Parameter(from, "input");
            var result    = Ex.Parameter(typeof(char[]), "result");
            var i         = workingType(from) == from ? input : Ex.Parameter(workingType(from), "i");
            var j         = Ex.Parameter(typeof(int), "j");
            var loopstart = Ex.Label("loopstart");
            var loopend   = Ex.Label("loopend");

            var loop = Ex.Block(
                Ex.Label(loopstart),
                Ex.IfThen(Ex.MakeBinary(ExpressionType.AndAlso,
                                        Ex.MakeBinary(ExpressionType.GreaterThan, j, Ex.Constant(0)),
                                        i.Type == typeof(BigInteger)
                        ? (Ex)Ex.Call(i, nameof(BigInteger.Equals), Type.EmptyTypes, Ex.Constant(BigInteger.Zero))
                        : Ex.MakeBinary(ExpressionType.Equal, i, Ex.Convert(Ex.Constant(0), i.Type))),
                          Ex.Goto(loopend)),
                Ex.Assign(
                    Ex.ArrayAccess(result, j),
                    Ex.ArrayIndex(Ex.Constant(_mapChars),
                                  Ex.Convert(Ex.MakeBinary(ExpressionType.And, i, Ex.Convert(Ex.Constant(0x3f), i.Type)), typeof(int)))),
                Ex.RightShiftAssign(i, Ex.Constant(6)),
                Ex.PostIncrementAssign(j),
                Ex.Goto(loopstart));
            var ret = Result(typeof(string),
                             Ex.New(typeof(string).GetTypeInfo().DeclaredConstructors
                                    .Select(c => new { c, p = c.GetParameters() })
                                    .First(c => c.p.Length == 3 && c.p[0].ParameterType == typeof(char[]) && c.p[1].ParameterType == typeof(int) && c.p[2].ParameterType == typeof(int)).c,
                                    result, Ex.Constant(0), j));
            var block = Ex.Block(Ex.Assign(j, Ex.Constant(0)),
                                 Ex.Assign(result, Ex.NewArrayBounds(typeof(char), Ex.Constant(charbound(from)))),
                                 loop,
                                 Ex.Label(loopend),
                                 ret);

            block = input == i
                ? Ex.Block(new[] { j, result },
                           block)
                : Ex.Block(new[] { i, j, result },
                           Ex.Assign(i, Ex.Convert(input, i.Type)),
                           block);

            return(Ex.Lambda(block, input));
        }
        public LambdaExpression CreateLambda(Type from, Type to)
        {
            var input     = Ex.Parameter(from, "input");
            var toString  = GetToString(from);
            var converter = Ref.GetLambda(typeof(string), to);
            var str       = Ex.Parameter(typeof(string), "str");
            Ex  block     = Ex.Block(new[] { str },
                                     Ex.Assign(str, Ex.Call(input, toString, toString.GetParameters().Select(pi => getParameter(pi, input)))),
                                     converter.ApplyTo(str));

            if (!from.GetTypeInfo().IsValueType)
            {
                block = Ex.Condition(Ex.MakeBinary(Et.Equal, input, Ex.Default(from)),
                                     NoResult(to),
                                     block);
            }
            var lambda = Ex.Lambda(block, input);

            return(lambda);
        }
Ejemplo n.º 18
0
        public LambdaExpression CreateLambda(Type from, Type to)
        {
            var input = Ex.Parameter(from, "input");
            var type  = Ex.Parameter(typeof(Type), "type");

            var block =
                Ex.Condition(
                    Ex.MakeBinary(Et.Equal, input, Ex.Default(typeof(object))),
                    NoResult(to),
                    Ex.Block(new[] { type },
                             Ex.Assign(type, Ex.Call(input, typeof(object).GetTypeInfo().GetDeclaredMethod(nameof(object.GetType)))),
                             Ex.Convert(Ex.Invoke(
                                            Ex.Call(Ex.Constant(Ref), nameof(IDataConverter.GetGeneralConverter), Type.EmptyTypes, type, Ex.Constant(to)),
                                            input),
                                        typeof(ConversionResult <>).MakeGenericType(to))));

            var lambda = Ex.Lambda(block, input);

            return(lambda);
        }
Ejemplo n.º 19
0
        private LambdaExpression createForCollection(Type from, Type to)
        {
            var cType = (from i in @from.GetTypeInfo().ImplementedInterfaces.Concat(new[] { @from })
                         where i.GetTypeInfo().IsInterface &&
                         i.GenericTypeArguments.Length == 1 &&
                         i.GetGenericTypeDefinition() == typeof(IReadOnlyCollection <>)
                         select i.GenericTypeArguments[0]).SingleOrDefault();

            if (cType == null)
            {
                return(null);
            }
            var toParameters  = to.GetTypeInfo().GenericTypeArguments;
            var input         = Ex.Parameter(from, "input");
            var getEnumerator = getGetEnumeratorMethod(from);
            var enumerator    = Ex.Parameter(getEnumerator.ReturnType, "enumerator");
            var eType         = getEnumerator.ReturnType.GetTypeInfo().GetDeclaredProperty(nameof(IEnumerator.Current)).PropertyType;
            var converters    = toParameters.Select(p => Ref.GetLambda(eType, p)).ToArray();

            var res        = toParameters.Select(p => Ex.Parameter(typeof(ConversionResult <>).MakeGenericType(p))).ToArray();
            var end        = Ex.Label(typeof(ConversionResult <>).MakeGenericType(to), "end");
            Ex  conversion = enumeratorConversion(to, enumerator, eType, converters, res, end);
            var block      = Ex.Block(res.Concat(new[] { enumerator }),
                                      Ex.IfThen(
                                          Ex.MakeBinary(Et.LessThan,
                                                        Ex.Property(input, typeof(IReadOnlyCollection <>).MakeGenericType(cType).GetTypeInfo()
                                                                    .GetDeclaredProperty(nameof(IReadOnlyCollection <object> .Count))),
                                                        Ex.Constant(TupleArity(to))),
                                          Ex.Goto(end, NoResult(to))),
                                      Ex.Assign(enumerator, Ex.Call(input, getEnumerator)),
                                      typeof(IDisposable).GetTypeInfo().IsAssignableFrom(enumerator.Type.GetTypeInfo())
                    ? (Ex)Ex.TryFinally(conversion,
                                        Ex.Call(enumerator, typeof(IDisposable).GetTypeInfo().GetDeclaredMethod(nameof(IDisposable.Dispose))))
                    : conversion,
                                      Ex.Label(end, Result(to, Ex.Call(Creator(to), res.Select(r => Ex.Property(r, nameof(IConversionResult.Result)))))));

            var lambda = Ex.Lambda(block, input);

            return(lambda);
        }
Ejemplo n.º 20
0
        public LambdaExpression CreateLambda(Type from, Type to)
        {
            var toString = GetToString(from);
            var input    = Ex.Parameter(from, "input");

            // Conversion from value types does not need to deal with null values.
            if (from.GetTypeInfo().IsValueType)
            {
                var block  = getResult(to, toString, input);
                var lambda = Ex.Lambda(block, input);
                return(lambda);
            }
            else
            {
                var inner = getResult(to, toString, input);
                var block = Ex.Condition(Ex.MakeBinary(Et.Equal, input, Ex.Default(from)),
                                         SucceedOnNull ? Result(to, Ex.Constant("")) : NoResult(to),
                                         inner);
                var lambda = Ex.Lambda(block, input);
                return(lambda);
            }
        }
Ejemplo n.º 21
0
        private LambdaExpression createForList(Type from, Type to)
        {
            var cType = (from i in @from.GetTypeInfo().ImplementedInterfaces.Concat(new[] { @from })
                         where i.GetTypeInfo().IsInterface &&
                         i.GenericTypeArguments.Length == 1 &&
                         i.GetGenericTypeDefinition() == typeof(IReadOnlyList <>)
                         select i.GenericTypeArguments[0]).SingleOrDefault();

            if (cType == null)
            {
                return(null);
            }
            var indexer      = typeof(IReadOnlyList <>).MakeGenericType(cType).GetTypeInfo().GetDeclaredProperty("Item");
            var count        = typeof(IReadOnlyCollection <>).MakeGenericType(cType).GetTypeInfo().GetDeclaredProperty(nameof(IReadOnlyCollection <object> .Count));
            var toParameters = to.GetTypeInfo().GenericTypeArguments;
            var input        = Ex.Parameter(from, "input");
            var converters   = toParameters.Select(p => Ref.GetLambda(cType, p)).ToArray();
            var res          = toParameters.Select(p => Ex.Parameter(typeof(ConversionResult <>).MakeGenericType(p))).ToArray();
            var end          = Ex.Label(typeof(ConversionResult <>).MakeGenericType(to), "end");

            var conversion = Ex.Block(converters.Select((c, i) =>
                                                        Ex.Block(
                                                            Ex.Assign(res[i],
                                                                      c.ApplyTo(Ex.MakeIndex(input, indexer, new[] { Ex.Constant(i) }))),
                                                            Ex.IfThen(Ex.Not(Ex.Property(res[i], nameof(IConversionResult.IsSuccessful))),
                                                                      Ex.Goto(end, NoResult(to))))));
            var block = Ex.Block(res,
                                 Ex.IfThen(
                                     Ex.MakeBinary(Et.LessThan,
                                                   Ex.Property(input, count),
                                                   Ex.Constant(toParameters.Length)),
                                     Ex.Goto(end, NoResult(to))),
                                 conversion,
                                 Ex.Label(end, Result(to, Ex.Call(Creator(to), res.Select(r => Ex.Property(r, nameof(IConversionResult.Result)))))));
            var lambda = Ex.Lambda(block, input);

            return(lambda);
        }
Ejemplo n.º 22
0
        protected override Expression VisitConditional(ConditionalExpression node)
        {
            Trace(MethodBase.GetCurrentMethod(), node);

            var testConstant = node.Test as ConstantExpression;

            if (testConstant != null)
            {
                // If this is a constant expression, evaluate it and visit the appropriate expression
                if (testConstant.Value is bool && (bool)testConstant.Value)
                {
                    return(base.Visit(node.IfTrue));
                }
                return(base.Visit(node.IfFalse));
            }


            // Transform the node into a binary expression like this:
            // A ? B : C = (A && B) || (!A && C)
            Expression transformed;

            try
            {
                var left  = Expression.MakeBinary(ExpressionType.AndAlso, node.Test, node.IfTrue);
                var right = Expression.MakeBinary(ExpressionType.AndAlso,
                                                  Expression.MakeUnary(ExpressionType.Not, node.Test, null), node.IfFalse);
                transformed = Expression.MakeBinary(ExpressionType.OrElse, left, right);
            }
            catch (Exception exc)
            {
                throw new Exception(
                          "Couldn't transform conditional expression into binary expressions. See inner exception for details.",
                          exc);
            }

            return(base.Visit(transformed));
        }
Ejemplo n.º 23
0
        private LambdaExpression setterLambda(Type from, Type to)
        {
            var valueType = recordCreator.GetValueType(from);
            var recType   = typeof(IRecord <>).MakeGenericType(valueType);
            var tryGet    = recType.GetTypeInfo().GetDeclaredMethod(nameof(IRecord <object> .TryGetValue));

            var input   = Ex.Parameter(from, "input");
            var rec     = Ex.Parameter(recType, "rec");
            var tmp     = Ex.Parameter(valueType, "tmp");
            var ctor    = GetParameterlessConstructor(to);
            var setters = GetWritablePropertiesForType(to);
            var res     = Ex.Parameter(to, "res");
            var pars    = setters.Select((p, i) => new
            {
                Converter = Ref.GetLambda(valueType, p.PropertyType),
                Var       = Ex.Parameter(typeof(ConversionResult <>).MakeGenericType(p.PropertyType), p.Name)
            }).ToArray();
            var end   = Ex.Label(typeof(ConversionResult <>).MakeGenericType(to), "end");
            var block = Ex.Block(new[] { tmp, res, rec }.Concat(pars.Select(x => x.Var)),
                                 Ex.Assign(res, Ex.New(ctor)),
                                 Ex.Assign(rec, recordCreator.Creator(from).ApplyTo(input)),
                                 Ex.Block(pars
                                          .Select(x =>
                                                  Ex.Block(
                                                      Ex.IfThen(
                                                          Ex.MakeBinary(ExpressionType.OrElse,
                                                                        Ex.Call(rec, tryGet, Ex.Constant(x.Var.Name), tmp),
                                                                        Ex.Call(rec, tryGet, Ex.Constant(ToCamelCase(x.Var.Name)), tmp)),
                                                          Ex.Block(
                                                              Ex.Assign(x.Var, x.Converter.ApplyTo(tmp)),
                                                              Ex.IfThenElse(Ex.Property(x.Var, nameof(IConversionResult.IsSuccessful)),
                                                                            Ex.Assign(Ex.Property(res, x.Var.Name), Ex.Property(x.Var, nameof(IConversionResult.Result))),
                                                                            Ex.Goto(end, NoResult(to)))))))),
                                 Ex.Label(end, Result(to, res)));

            return(Ex.Lambda(block, input));
        }
Ejemplo n.º 24
0
        private static Expression MakeBinary(ExpressionType type, Expression left, string value)
        {
            object typedValue = value;

            if (left.Type != typeof(string))
            {
                if (string.IsNullOrEmpty(value))
                {
                    typedValue = null;
                    if (Nullable.GetUnderlyingType(left.Type) == null)
                    {
                        left = Expression.Convert(left, typeof(Nullable <>).MakeGenericType(left.Type));
                    }
                }
                else
                {
                    typedValue = Convert.ChangeType(value, Nullable.GetUnderlyingType(left.Type) ?? left.Type);
                }
            }

            var right = Expression.Constant(typedValue, left.Type);

            return(Expression.MakeBinary(type, left, right));
        }
        private LambdaExpression fromConvertLambda(Type from)
        {
            var input     = Ex.Parameter(from, "input");
            var converted = Ex.Parameter(typeof(ConversionResult <string[]>), "converted");
            var converter = Ref.GetLambda(from, typeof(string[]));
            var result    = Ex.Call((from mi in typeof(string).GetTypeInfo().GetDeclaredMethods(nameof(string.Join))
                                     let par = mi.GetParameters()
                                               where par.Length == 2 && par[0].ParameterType == typeof(string) && par[1].ParameterType == typeof(string[])
                                               select mi).Single(),
                                    Ex.Constant(Separators[0].ToString()), Ex.Property(converted, nameof(IConversionResult.Result)));
            var block = Ex.Block(new[] { converted },
                                 Ex.Assign(converted, converter.ApplyTo(input)),
                                 Ex.Condition(
                                     Ex.MakeBinary(Et.AndAlso,
                                                   Ex.Property(converted, nameof(IConversionResult.IsSuccessful)),
                                                   Ex.MakeBinary(Et.GreaterThan,
                                                                 Ex.Property(Ex.Property(converted, nameof(IConversionResult.Result)), nameof(Array.Length)),
                                                                 Ex.Constant(0))),
                                     Result(typeof(string), result),
                                     NoResult(typeof(string))));
            var lambda = Ex.Lambda(block, input);

            return(lambda);
        }
Ejemplo n.º 26
0
 public static Expression BinaryWith(this Expression left, ExpressionType operation, Expression right)
 => Expression.MakeBinary(operation, left, right);
Ejemplo n.º 27
0
 protected override Expression VisitBinary(BinaryExpression node) =>
 Linearize(exs => Ex.MakeBinary(node.NodeType, exs[0], exs[1]), node.Left, node.Right);
Ejemplo n.º 28
0
 /// <inheritdoc />
 protected override Expression VisitBinary(BinaryExpression b) => Expression.MakeBinary(b.NodeType, Visit(b.Left), Visit(b.Right));
        /// <summary>
        /// Invoke the specified operation.
        /// </summary>
        /// <param name="parameters">The parameter set to action.</param>
        /// <returns>The result of the operation.</returns>
        public Resource Invoke(Parameters parameters)
        {
            var configuration = RestOperationContext.Current.IncomingRequest.QueryString["_configurationName"];

            // validate query parameters
            if (string.IsNullOrEmpty(configuration))
            {
                throw new InvalidOperationException("No resource merge configuration specified. Use the ?_configurationName parameter specify a configuration.");
            }

            var  countParameter  = RestOperationContext.Current.IncomingRequest.QueryString["_count"];
            var  offsetParameter = RestOperationContext.Current.IncomingRequest.QueryString["_offset"];
            uint offset          = 0;
            uint count           = 1000;

            if (!string.IsNullOrEmpty(offsetParameter) && !uint.TryParse(offsetParameter, out offset))
            {
                throw new InvalidOperationException("Invalid value for _offset. The _offset value must be a positive integer.");
            }

            if (!string.IsNullOrEmpty(countParameter) && !uint.TryParse(countParameter, out count))
            {
                throw new InvalidOperationException("Invalid value for _count. The _count value must be a positive integer.");
            }

            var linkSource       = RestOperationContext.Current.IncomingRequest.QueryString["linkSource"]?.ToUpperInvariant();
            var matchResult      = RestOperationContext.Current.IncomingRequest.QueryString["matchResult"]?.ToUpperInvariant();
            var masterResourceId = RestOperationContext.Current.IncomingRequest.QueryString["goldenResourceId"]?.ToUpperInvariant();
            var resourceId       = RestOperationContext.Current.IncomingRequest.QueryString["resourceId"]?.ToUpperInvariant();

            if (!string.IsNullOrEmpty(linkSource) && !linkSourceMap.ContainsKey(linkSource))
            {
                throw new InvalidOperationException($"Invalid value for linkSource: '{linkSource}'. The link source must be one of the following values: {string.Join(", ", linkSourceMap.Keys)}.");
            }

            if (!string.IsNullOrEmpty(matchResult) && !matchResultMap.ContainsKey(matchResult))
            {
                throw new InvalidOperationException($"Invalid value for matchResult: '{matchResult}'. The match result must be one of the following values: {string.Join(", ", matchResultMap.Keys)}.");
            }

            var matchingService = ApplicationServiceContext.Current.GetService <IRecordMatchingService>();

            if (matchingService == null)
            {
                throw new InvalidOperationException("No record matching service found");
            }

            var entityRelationshipService = ApplicationServiceContext.Current.GetService <IRepositoryService <EntityRelationship> >();
            var patientService            = ApplicationServiceContext.Current.GetService <IRepositoryService <Patient> >();
            var cacheService = ApplicationServiceContext.Current.GetService <IAdhocCacheService>();

            Expression <Func <EntityRelationship, bool> > queryExpression = c => c.ObsoleteVersionSequenceId == null;

            // add the match result filter
            if (string.IsNullOrEmpty(matchResult))
            {
                queryExpression = c => (c.RelationshipTypeKey == MdmConstants.MasterRecordRelationship ||
                                        c.RelationshipTypeKey == MdmConstants.CandidateLocalRelationship ||
                                        c.RelationshipTypeKey == MdmConstants.IgnoreCandidateRelationship) && c.ObsoleteVersionSequenceId == null;
            }
            else if (!string.IsNullOrEmpty(matchResult) && matchResultMap.TryGetValue(matchResult, out var matchResultKey))
            {
                var updatedExpression = Expression.MakeBinary(ExpressionType.AndAlso, queryExpression.Body,
                                                              Expression.MakeBinary(ExpressionType.Equal,
                                                                                    Expression.Property(Expression.Parameter(typeof(EntityRelationship)), typeof(EntityRelationship), nameof(EntityRelationship.RelationshipTypeKey)),
                                                                                    Expression.Constant(matchResultKey, typeof(Guid?))));

                queryExpression = Expression.Lambda <Func <EntityRelationship, bool> >(updatedExpression, queryExpression.Parameters);
            }

            // add the link source filter
            if (!string.IsNullOrEmpty(linkSource) && linkSourceMap.TryGetValue(linkSource, out var linkSourceKey))
            {
                var updatedExpression = Expression.MakeBinary(ExpressionType.AndAlso, queryExpression.Body,
                                                              Expression.MakeBinary(ExpressionType.Equal,
                                                                                    Expression.Property(Expression.Parameter(typeof(EntityRelationship)), typeof(EntityRelationship), nameof(EntityRelationship.ClassificationKey)),
                                                                                    Expression.Constant(linkSourceKey, typeof(Guid?))));

                queryExpression = Expression.Lambda <Func <EntityRelationship, bool> >(updatedExpression, queryExpression.Parameters);
            }

            // add the target key filter
            if (Guid.TryParse(masterResourceId, out var targetKey))
            {
                var updatedExpression = Expression.MakeBinary(ExpressionType.AndAlso, queryExpression.Body,
                                                              Expression.MakeBinary(ExpressionType.Equal,
                                                                                    Expression.Property(Expression.Parameter(typeof(EntityRelationship)), typeof(EntityRelationship), nameof(EntityRelationship.TargetEntityKey)),
                                                                                    Expression.Constant(targetKey, typeof(Guid?))));

                queryExpression = Expression.Lambda <Func <EntityRelationship, bool> >(updatedExpression, queryExpression.Parameters);
            }

            // add the source key filter
            if (Guid.TryParse(resourceId, out var sourceKey))
            {
                var updatedExpression = Expression.MakeBinary(ExpressionType.AndAlso, queryExpression.Body,
                                                              Expression.MakeBinary(ExpressionType.Equal,
                                                                                    Expression.Property(Expression.Parameter(typeof(EntityRelationship)), typeof(EntityRelationship), nameof(EntityRelationship.SourceEntityKey)),
                                                                                    Expression.Constant(sourceKey, typeof(Guid?))));

                queryExpression = Expression.Lambda <Func <EntityRelationship, bool> >(updatedExpression, queryExpression.Parameters);
            }

            // query the underlying service
            var relationships = entityRelationshipService.Find(queryExpression, (int)offset, (int?)count, out var totalResults, null);

            var resource = new Parameters();

            var previousOffset = (int)offset - (int)count < 0 ? 0 : (int)offset - (int)count;

            var builder = new StringBuilder();

            // rebuild the outgoing query string
            foreach (var key in RestOperationContext.Current.IncomingRequest.QueryString.AllKeys.Intersect(this.Parameters.Keys).Where(c => c != "_count" && c != "_offset"))
            {
                builder.Append($"&{key}={RestOperationContext.Current.IncomingRequest.QueryString[key]}");
            }

            var queryParameters = builder.ToString();

            if (offset > 0 && totalResults > 0)
            {
                resource.Parameter.Add(new Parameters.ParameterComponent
                {
                    Name  = "prev",
                    Value = new FhirUri($"{RestOperationContext.Current.IncomingRequest.Url.GetLeftPart(UriPartial.Authority)}{RestOperationContext.Current.IncomingRequest.Url.LocalPath}?_offset={previousOffset}&_count={count}{queryParameters}")
                });
            }

            resource.Parameter.Add(new Parameters.ParameterComponent
            {
                Name  = "self",
                Value = new FhirUri(RestOperationContext.Current.IncomingRequest.Url)
            });

            if (offset + count < totalResults)
            {
                resource.Parameter.Add(new Parameters.ParameterComponent
                {
                    Name  = "next",
                    Value = new FhirUri($"{RestOperationContext.Current.IncomingRequest.Url.GetLeftPart(UriPartial.Authority)}{RestOperationContext.Current.IncomingRequest.Url.LocalPath}?_offset={offset + count}&_count={count}{queryParameters}")
                });
            }

            // build the result set
            foreach (var entityRelationship in relationships)
            {
                var patient = entityRelationship.TargetEntity as Patient ?? cacheService?.Get <Patient>(entityRelationship.TargetEntityKey.ToString());

                if (patient == null)
                {
                    patient = patientService.Get(entityRelationship.TargetEntityKey.Value);
                }

                cacheService?.Add(entityRelationship.TargetEntityKey.ToString(), patient);

                var classificationResult = matchingService.Classify(patient, new List <Patient>
                {
                    new Patient
                    {
                        Key = entityRelationship.SourceEntityKey
                    }
                }, configuration).FirstOrDefault();

                if (classificationResult == null)
                {
                    continue;
                }

                resource.Parameter.Add(new Parameters.ParameterComponent
                {
                    Name = "link",
                    Part = new List <Parameters.ParameterComponent>
                    {
                        new Parameters.ParameterComponent
                        {
                            Name  = "goldenResourceId",
                            Value = new FhirString($"Patient/{entityRelationship.TargetEntityKey}")
                        },
                        new Parameters.ParameterComponent
                        {
                            Name  = "sourceResourceId",
                            Value = new FhirString($"Patient/{classificationResult.Record.Key}")
                        },
                        new Parameters.ParameterComponent
                        {
                            Name  = "matchResult",
                            Value = new FhirString(matchResultMap.First(c => c.Value == entityRelationship.RelationshipTypeKey).Key)
                        },
                        new Parameters.ParameterComponent
                        {
                            Name  = "linkSource",
                            Value = new FhirString(linkSourceMap.First(c => c.Value == entityRelationship.ClassificationKey).Key)
                        },
                        new Parameters.ParameterComponent
                        {
                            Name  = "score",
                            Value = new FhirDecimal(Convert.ToDecimal(classificationResult.Score))
                        }
                    }
                });
            }

            resource.Parameter.Add(new Parameters.ParameterComponent
            {
                Name  = "resultCount",
                Value = new Integer(resource.Parameter.Count(c => c.Name == "link"))
            });

            resource.Parameter.Add(new Parameters.ParameterComponent
            {
                Name  = "totalResults",
                Value = new Integer(totalResults)
            });

            return(resource);
        }
Ejemplo n.º 30
0
        protected virtual Expression VisitBinary(BinaryExpression b)
        {
            var left       = Visit(b.Left);
            var right      = Visit(b.Right);
            var conversion = Visit(b.Conversion);

            if (left != b.Left || right != b.Right || conversion != b.Conversion)
            {
                return(b.NodeType == ExpressionType.Coalesce && b.Conversion != null?Expression.Coalesce(left, right, conversion as LambdaExpression) : Expression.MakeBinary(b.NodeType, left, right, b.IsLiftedToNull, b.Method));
            }
            return(b);
        }