public string GetValue(IContext <string> context)
        {
            if (overridePropFunc != null && overridePropFunc.TryGetValue(propName, out var func))
            {
                return(monad.Lift(func()));
            }

            var finalPropOrMethod = $"({context.Value}.{propName})";

            return(monad.Lift($"(CSharpHelper.IsNumber({finalPropOrMethod}) " +
                              $"? ((double)({finalPropOrMethod})) " +
                              $": ({finalPropOrMethod}))"));
        }
        public TMonad GetValue(IContext <TMonad> context)
        {
            var oc   = context as ObjectContext <TMonad>;
            var type = oc.Object?.GetType();

            if (!propSet || prop?.DeclaringType != type)
            {
                prop    = type?.GetProperty(propName);
                propSet = true;
            }
            return(prop == null
                ? monad.Unit
                : monad.Lift(prop?.GetValue(oc.Object)));
        }
        public string GetValue(IContext <string> context)
        {
            if (overridePropertyFunc != null && overridePropertyFunc.TryGetValue(propName, out var func))
            {
                return(monad.Lift(func()));
            }

            string finalPropOrMethod = propName;

            if (Regex.Match(context.Value, jsDateObjPattern).Success&& jsDatePropertyMethods.TryGetValue(propName, out var jsDateMethod))
            {
                finalPropOrMethod = jsDateMethod;
            }

            if (context.Value.Contains(Constants.DefaultContext))
            {
                return($"{Constants.DefaultContext}.{finalPropOrMethod}");
            }

            return(monad.Lift(context.Value == "{ }"
                ? $"{Constants.DefaultContext}.{finalPropOrMethod}"
                : $"{context.Value}.{finalPropOrMethod}"));
        }
示例#4
0
 public ValueExpr(IMonad <TMonad> monad, object value)
 {
     Monad      = monad;
     this.value = Monad.Lift(value);
 }