Пример #1
0
        public static string NextArg(CIterator <string> iter)
        {
            if (iter.HasNext())
            {
                string arg = CStringUtils.UnArg(iter.Next());
                if (!IsValidArg(arg))
                {
                    throw new CCommandException("Invalid arg: " + arg);
                }

                return(arg);
            }

            throw new CCommandException("Unexpected end of args");
        }
Пример #2
0
        private static object ResolveInvokeParameter(ParameterInfo param, CIterator <string> iter)
        {
            if (param.IsOptional && !iter.HasNext())
            {
                return(param.DefaultValue);
            }

            Type type = param.ParameterType;

            if (type == typeof(string[]))
            {
                List <string> values = new List <string>();
                while (iter.HasNext())
                {
                    values.Add(NextArg(iter));
                }
                return(values.ToArray());
            }

            if (type == typeof(string))
            {
                return(NextArg(iter));
            }

            if (type == typeof(float))
            {
                return(NextFloatArg(iter));
            }

            if (type == typeof(int))
            {
                return(NextIntArg(iter));
            }

            if (type == typeof(bool))
            {
                return(NextBoolArg(iter));
            }

            if (type == typeof(Vector2))
            {
                float x = NextFloatArg(iter);
                float y = NextFloatArg(iter);

                return(new Vector2(x, y));
            }

            if (type == typeof(Vector3))
            {
                float x = NextFloatArg(iter);
                float y = NextFloatArg(iter);
                float z = NextFloatArg(iter);

                return(new Vector3(x, y, z));
            }

            if (type == typeof(Vector4))
            {
                float x = NextFloatArg(iter);
                float y = NextFloatArg(iter);
                float z = NextFloatArg(iter);
                float w = NextFloatArg(iter);

                return(new Vector4(x, y, z, w));
            }

            if (type == typeof(int[]))
            {
                List <int> values = new List <int>();
                while (iter.HasNext())
                {
                    values.Add(NextIntArg(iter));
                }
                return(values.ToArray());
            }

            if (type == typeof(float[]))
            {
                List <float> values = new List <float>();
                while (iter.HasNext())
                {
                    values.Add(NextFloatArg(iter));
                }
                return(values.ToArray());
            }

            if (type == typeof(bool[]))
            {
                List <bool> values = new List <bool>();
                while (iter.HasNext())
                {
                    values.Add(NextBoolArg(iter));
                }
                return(values.ToArray());
            }

            throw new CCommandException("Unsupported value type: " + type);
        }