Ejemplo n.º 1
0
        public static Result <string> IsLessEqual(OneCallContext context,
                                                  string ns, object self, object[] arguments)
        {
            if (self == null)
            {
                return(RequireNotNull());
            }

            var prop = GetProp(self, arguments[0]);

            if (prop == null)
            {
                return(RequirePropNotNull(arguments[0]));
            }

            var val     = GetPropValue(self, arguments[0]);
            var compare = Convert.ToDouble(arguments[1]);

            if (Convert.ToDouble(val) <= compare)
            {
                return(MacroUtil.EvalToString(arguments[2], context, self));
            }

            return(Empty);
        }
Ejemplo n.º 2
0
        public static Result <string> IsNotEqual(OneCallContext context,
                                                 string ns, object self, object[] arguments)
        {
            if (self == null)
            {
                return(RequireNotNull());
            }

            var prop = GetProp(self, arguments[0]);

            if (prop == null)
            {
                return(Empty);
            }

            var val     = GetPropValue(self, arguments[0]);
            var compare = arguments[1];

            if (!IsEqual(val, compare))
            {
                return(MacroUtil.EvalToString(arguments[2], context, self));
            }

            return(Empty);
        }
Ejemplo n.º 3
0
        public static Result <string> HasProp(SdmapCompilerContext context,
                                              string ns, object self, object[] arguments)
        {
            if (self == null)
            {
                return(RequireNotNull());
            }

            var prop = GetProp(self, arguments[0]);

            if (prop != null)
            {
                return(MacroUtil.EvalToString(arguments[1], context, self));
            }

            return(Empty);
        }
Ejemplo n.º 4
0
        public static Result <string> Each(OneCallContext context,
                                           string ns, object self, object[] arguments)
        {
            if (self == null)
            {
                return(RequireNotNull());
            }
            var prop = GetProp(self, arguments[0]);

            if (prop == null)
            {
                return(RequirePropNotNull(arguments[0]));
            }

            string syntax = (string)arguments[0];
            var    val    = GetPropValue(self, syntax);

            if (val == null)
            {
                return(Empty);
            }
            else if (!(val is IEnumerable))
            {
                return(RequirePropType(prop, "IEnumerable"));
            }
            else
            {
                var result = new StringBuilder();
                foreach (var newSelf in val as IEnumerable)
                {
                    if (result.Length > 0)
                    {
                        result.Append(arguments[1]);
                    }
                    var one = MacroUtil.EvalToString(arguments[2], context, newSelf);
                    if (one.IsFailure)
                    {
                        return(one);
                    }
                    result.Append(one.Value);
                }
                return(Result.Ok(result.ToString()));
            }
        }
Ejemplo n.º 5
0
        public static Result <string> IsNotEmpty(OneCallContext context,
                                                 string ns, object self, object[] arguments)
        {
            if (self == null)
            {
                return(RequireNotNull());
            }

            var prop = GetProp(self, arguments[0]);

            if (prop == null)
            {
                return(RequirePropNotNull(arguments[0]));
            }

            if (!IsEmpty(GetPropValue(self, arguments[0])))
            {
                return(MacroUtil.EvalToString(arguments[1], context, self));
            }
            return(Empty);
        }
Ejemplo n.º 6
0
        public static Result <string> IsNotLike(SdmapCompilerContext context,
                                                string ns, object self, object[] arguments)
        {
            if (self == null)
            {
                return(RequireNotNull());
            }

            var prop = GetProp(self, arguments[0]);

            if (prop == null)
            {
                return(Empty);
            }

            var val = GetPropValue(self, arguments[0]) as string;

            if (!Regex.IsMatch(val, (string)arguments[1]))
            {
                return(MacroUtil.EvalToString(arguments[2], context, self));
            }
            return(Empty);
        }
Ejemplo n.º 7
0
        public static Result <string> IsNull(OneCallContext context,
                                             string ns, object self, object[] arguments)
        {
            if (self == null)
            {
                return(RequireNotNull());
            }

            var prop = GetProp(self, arguments[0]);

            if (prop == null)
            {
                return(Result.Ok(string.Empty));
            }

            string syntax = (string)arguments[0];

            if (GetPropValue(self, syntax) == null)
            {
                return(MacroUtil.EvalToString(arguments[1], context, self));
            }

            return(Empty);
        }