Ejemplo n.º 1
0
        public static CallScope Create(string parm)
        {
            CallScope callScope = new CallScope(new EmptyScope());

            callScope.PushBack(NValue.StringValue(parm));
            return(callScope);
        }
Ejemplo n.º 2
0
 public Value Handler(CallScope args)
 {
     if (WantsArg)
     {
         if (args.Size < 2)
         {
             throw new InvalidOperationException(String.Format("No argument provided for {0}", Desc));
         }
         if (args.Size > 2)
         {
             throw new InvalidOperationException(String.Format("To many arguments provided for {0}", Desc));
         }
         if (args[0].Type != ValueTypeEnum.String)
         {
             throw new InvalidOperationException(String.Format("Context argument for {0} not a string", Desc));
         }
         On(args[0].AsString, args[1].AsString);
     }
     else
     {
         if (args.Size < 1)
         {
             throw new InvalidOperationException(String.Format("No argument provided for {0}", Desc));
         }
         if (args[0].Type != ValueTypeEnum.String)
         {
             throw new InvalidOperationException(String.Format("Context argument for {0} not a string", Desc));
         }
         On(args[0].AsString);
     }
     return(NValue.Get(true));
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Ported from void process_option(const string& whence, const expr_t::func_t& opt,
        /// </summary>
        public static void ProcessOption(string whence, ExprFunc opt, Scope scope, string arg, string name)
        {
            try
            {
                CallScope args = new CallScope(scope);

                args.PushBack(NValue.Get(whence));
                if (!String.IsNullOrEmpty(arg))
                {
                    args.PushBack(NValue.Get(arg));
                }

                opt(args);
            }
            catch (CountError)
            {
                throw; // DM - error_count is not std::exception and may pass by "catch" block
            }
            catch (Exception)
            {
                if (!String.IsNullOrEmpty(name) && name.StartsWith("-"))
                {
                    throw new Exception(String.Format("While parsing option '{0}'", name));
                }
                else
                {
                    throw new Exception(String.Format("While parsing environent variable '{0}'", name));
                }
            }
        }
Ejemplo n.º 4
0
        public static void ProcessOption(string whence, ExprFunc opt, Scope scope, string arg, string name)
        {
            try
            {
                CallScope args = new CallScope(scope);

                args.PushBack(NValue.Get(whence));
                if (!String.IsNullOrEmpty(arg))
                {
                    args.PushBack(NValue.Get(arg));
                }

                opt(args);
            }
            catch
            {
                if (!String.IsNullOrEmpty(name) && name.StartsWith("-"))
                {
                    throw new Exception(String.Format("While parsing option '{0}'", name));
                }
                else
                {
                    throw new Exception(String.Format("While parsing environent variable '{0}'", name));
                }
            }
        }
Ejemplo n.º 5
0
 public bool Has <T>(int index)
 {
     if (index < Size)
     {
         Resolve(index, NValue.GetValueType <T>(), false);
         return(!NValue.IsNullOrEmpty(ArgsList[index]));
     }
     return(false);
 }
Ejemplo n.º 6
0
        // operator()
        public Value Call(CallScope args)
        {
            if (!args.IsEmpty)
            {
                args.PushFront(NValue.StringValue("?expr"));
                return(Handler(args));
            }

            if (WantsArg)
            {
                return(NValue.StringValue(Value));
            }
            else
            {
                return(NValue.Get(Handled));
            }
        }
Ejemplo n.º 7
0
        public T Get <T>(int index, bool convert = true)
        {
            // DM - this method was completely rewritten to handle conversion to the expected type
            // #remove-boxing - Consider removing excess boxing in this method.

            if (typeof(T) == typeof(int))
            {
                convert = true; // see - inline int call_scope_t::get<int>(std::size_t index, bool) {
            }
            if (typeof(T) == typeof(ExprOp))
            {
                return((T)(object)Args.AsSequence[index].AsAny <ExprOp>()); // see - call_scope_t::get<expr_t::ptr_op_t>(std::size_t index, bool)
            }
            ValueTypeEnum valType = NValue.GetValueType <T>();
            Value         val     = Resolve(index, NValue.GetValueType <T>(), !convert);

            switch (valType)
            {
            case ValueTypeEnum.Amount: return((T)(object)val.AsAmount);

            case ValueTypeEnum.Any: return(val.AsAny <T>());

            case ValueTypeEnum.Balance: return((T)(object)val.AsBalance);

            case ValueTypeEnum.Boolean: return((T)(object)val.AsBoolean);

            case ValueTypeEnum.Date: return((T)(object)val.AsDate);

            case ValueTypeEnum.DateTime: return((T)(object)val.AsDateTime);

            case ValueTypeEnum.Integer: return((T)Convert.ChangeType(val.AsLong, typeof(T)));

            case ValueTypeEnum.Mask: return((T)(object)val.AsMask);

            case ValueTypeEnum.Scope: return((T)(object)val.AsScope);

            case ValueTypeEnum.Sequence: return((T)(object)val.AsSequence);

            case ValueTypeEnum.String: return((T)(object)val.AsString);

            case ValueTypeEnum.Void: return(default(T));

            default: return(default(T));
            }
        }
Ejemplo n.º 8
0
 public bool Has(int index)
 {
     return(index < Size && !(NValue.IsNullOrEmpty(ArgsList[index])));
 }