コード例 #1
0
        public static ValueType GetFhirType(this IFluentPathValue value)
        {
            if (value == null || value.Value == null)
            {
                throw Error.ArgumentNull("value");
            }

            var val = value.Value;

            if (val is Boolean)
            {
                return(ValueType.Boolean);
            }
            if (val is String)
            {
                return(ValueType.String);
            }
            if (val is Int64)
            {
                return(ValueType.Integer);
            }
            if (val is Decimal)
            {
                return(ValueType.Decimal);
            }
            if (val is PartialDateTime)
            {
                return(ValueType.DateTime);
            }

            throw new InvalidOperationException("IFhirPathValue.Value returned an unsupported type {0}".FormatWith(val.GetType().Name));
        }
コード例 #2
0
 public static bool AsBoolean(this IFluentPathValue me)
 {
     if (me.Value == null)
     {
         throw Error.ArgumentNull("me");
     }
     return((bool)me.Value);
 }
コード例 #3
0
 public static decimal AsDecimal(this IFluentPathValue me)
 {
     if (me.Value == null)
     {
         throw Error.ArgumentNull("me");
     }
     return((decimal)me.Value);
 }
コード例 #4
0
 public static Int64 AsInteger(this IFluentPathValue me)
 {
     if (me.Value == null)
     {
         throw Error.ArgumentNull("me");
     }
     return((Int64)me.Value);
 }
コード例 #5
0
        //public static IEnumerable<IFhirPathElement> Child(this IEnumerable<IFhirPathValue> focus, string name)
        //{
        //    return focus.JustFhirPathElements().Child(name);
        //}

        //public static IEnumerable<IFhirPathElement> Child(this IEnumerable<IFhirPathElement> focus, string name)
        //{
        //    return focus.SelectMany(node => node.Children().Where(child => child.IsMatch(name)));
        //}


        public static IEnumerable <IFluentPathElement> Children(this IFluentPathValue focus)
        {
            if (focus is IFluentPathElement)
            {
                return(((IFluentPathElement)focus).Children().Select(c => c.Child));
            }

            return(Enumerable.Empty <IFluentPathElement>());
        }
コード例 #6
0
        public static bool IsEqualTo(this IFluentPathValue left, IFluentPathValue right)
        {
            if (!Object.Equals(left.Value, right.Value))
            {
                return(false);
            }

            return(left.Children().IsEqualTo(right.Children()).AsBoolean());
        }
コード例 #7
0
        private static IFluentPathValue math(this IFluentPathValue left, Func <dynamic, dynamic, object> f, IFluentPathValue right)
        {
            if (left.Value == null || right.Value == null)
            {
                throw Error.InvalidOperation("Operands must both be values");
            }
            if (left.Value.GetType() != right.Value.GetType())
            {
                throw Error.InvalidOperation("Operands must be of the same type");
            }

            return(new TypedValue(f(left.Value, right.Value)));
        }
コード例 #8
0
        public static bool IsEquivalentTo(this IFluentPathValue left, IFluentPathValue right)
        {
            // Exception: In equality comparisons, the "id" elements do not need to be equal
            if (left is IFluentPathElement && right is IFluentPathElement)
            {
                var lElem = (IFluentPathElement)left;
                var rElem = (IFluentPathElement)right;

                //  if (lElem.Name == "id" && rElem.Name == "id")
                return(true);
            }

            throw new NotImplementedException();
        }
コード例 #9
0
        /// <summary>
        /// A String representation of the entity that will convert whatever type it is into a string
        /// (unlike the AsString, which just cases to a string)
        /// </summary>
        /// <param name="me"></param>
        /// <returns></returns>
        public static string AsStringRepresentation(this IFluentPathValue me)
        {
            if (me.Value == null)
            {
                return(null);
            }

            if (me.Value is PartialDateTime)
            {
                return(me.Value.ToString());
            }
            else
            {
                return(PrimitiveTypeConverter.ConvertTo <string>(me.Value));
            }
        }
コード例 #10
0
        private static bool compare(this IFluentPathValue left, InfixOperator comp, IFluentPathValue right)
        {
            if (left.Value == null || right.Value == null)
            {
                throw Error.InvalidOperation("'{0)' requires both operands to be values".FormatWith(comp));
            }
            if (left.Value.GetType() != right.Value.GetType())
            {
                throw Error.InvalidOperation("Operands to '{0}' must be of the same type".FormatWith(comp));
            }

            if (left.Value is string)
            {
                var result = String.Compare(left.AsString(), right.AsString());
                if (comp == InfixOperator.LessThan)
                {
                    return(result == -1);
                }
                if (comp == InfixOperator.GreaterThan)
                {
                    return(result == 1);
                }
            }
            else
            {
                if (comp == InfixOperator.LessThan)
                {
                    return((dynamic)left.Value < (dynamic)right.Value);
                }
                if (comp == InfixOperator.GreaterThan)
                {
                    return((dynamic)left.Value > (dynamic)right.Value);
                }
            }

            throw Error.InvalidOperation("Comparison failed on operator '{0}'".FormatWith(comp));
        }
コード例 #11
0
 public static bool Predicate(this Evaluator evaluator, IFluentPathValue instance, IEvaluationContext context)
 {
     return(evaluator.Evaluate(instance, context).BooleanEval().AsBoolean());
 }
コード例 #12
0
 public static object Scalar(this Evaluator evaluator, IFluentPathValue instance)
 {
     return(evaluator.Evaluate(instance, new BaseEvaluationContext()).SingleValue());
 }
コード例 #13
0
        public static IEnumerable <IFluentPathValue> Evaluate(this Evaluator evaluator, IFluentPathValue instance)
        {
            var original = FhirValueList.Create(instance);

            return(evaluator.Evaluate(instance, new BaseEvaluationContext()));
        }
コード例 #14
0
        public static IEnumerable <IFluentPathValue> Evaluate(this Evaluator evaluator, IFluentPathValue instance, IEvaluationContext context)
        {
            var original = FhirValueList.Create(instance);

            context.OriginalContext = original;
            return(evaluator(original, context));
        }
コード例 #15
0
        public static bool Predicate(string expression, IFluentPathValue instance)
        {
            var evaluator = Compile(expression);

            return(evaluator.Predicate(instance, new BaseEvaluationContext()));
        }
コード例 #16
0
        public static object Scalar(string expression, IFluentPathValue instance)
        {
            var evaluator = Compile(expression);

            return(evaluator.Scalar(instance, new BaseEvaluationContext()));
        }
コード例 #17
0
 public static IFluentPathValue GreaterThan(this IFluentPathValue left, IFluentPathValue right)
 {
     return(new TypedValue(left.compare(InfixOperator.GreaterThan, right)));
 }
コード例 #18
0
 public static IFluentPathValue LessOrEqual(this IFluentPathValue left, IFluentPathValue right)
 {
     return(new TypedValue(left.IsEqualTo(right) || left.compare(InfixOperator.LessThan, right)));
 }
コード例 #19
0
 public static PartialDateTime AsDateTime(this IFluentPathValue me)
 {
     return((PartialDateTime)me.Value);
 }
コード例 #20
0
 /// <summary>
 /// Cast this value to a string (not ToString, consider AsStringRepresentation if you want that)
 /// </summary>
 /// <param name="me"></param>
 /// <returns></returns>
 public static string AsString(this IFluentPathValue me)
 {
     return((string)me.Value);
 }
コード例 #21
0
 public static bool IsTrue(this Evaluator evaluator, IFluentPathValue instance)
 {
     return(evaluator.Evaluate(instance, new BaseEvaluationContext()).BooleanEval().AsBoolean());
 }
コード例 #22
0
 public static IFluentPathValue Div(this IFluentPathValue left, IFluentPathValue right)
 {
     return(left.math((a, b) => a / b, right));
 }
コード例 #23
0
        public static IEnumerable <IFluentPathValue> Evaluate(string expression, IFluentPathValue instance)
        {
            var evaluator = Compile(expression);

            return(evaluator(FhirValueList.Create(instance), new BaseEvaluationContext()));
        }