コード例 #1
0
ファイル: MemberAccessor.cs プロジェクト: 0xFh/Asda2-Project
        public MemberInfo ModPropValue <T>(U user, object obj, string name, Type type, string delta,
                                           StringParser.OperatorHandler <T> oper, ref T newValue)
        {
            object     propHolder;
            MemberInfo prop = GetProp(user, obj, name, type, out propHolder);

            if (prop != null)
            {
                object obj1 = null;
                if (StringParser.Parse(delta, prop.GetVariableType(), ref obj1))
                {
                    object unindexedValue = prop.GetUnindexedValue(obj);
                    prop.SetUnindexedValue(propHolder, newValue = oper((T)unindexedValue, (T)obj1));
                    return(prop);
                }
            }

            return(null);
        }
コード例 #2
0
ファイル: StringParser.cs プロジェクト: uvbs/Asda2-Server
        /// <summary>
        /// Evaluates the given (simple) expression
        ///
        /// TODO: Use Polish Notation to allow more efficiency and complexity
        /// TODO: Add operator priority
        /// </summary>
        public static bool Eval(Type valType, ref long val, string expr, ref object error, bool startsWithOperator)
        {
            string[] strArray = expr.Split(new char[1] {
                ' '
            }, StringSplitOptions.RemoveEmptyEntries);
            bool flag = startsWithOperator;

            StringParser.OperatorHandler <long> operatorHandler = (StringParser.OperatorHandler <long>)null;
            foreach (string str1 in strArray)
            {
                string str2 = str1.Trim();
                if (flag)
                {
                    if (!StringParser.IntOperators.TryGetValue(str2, out operatorHandler))
                    {
                        error = (object)("Invalid operator: " + str2);
                        return(false);
                    }
                }
                else
                {
                    object obj = (object)null;
                    if (!StringParser.Parse(str2, valType, ref obj))
                    {
                        error = (object)("Could not convert value \"" + str2 + "\" to Type \"" + (object)valType +
                                         "\"");
                        return(false);
                    }

                    long y = (long)Convert.ChangeType(obj, typeof(long));
                    val = operatorHandler == null ? y : operatorHandler(val, y);
                }

                flag = !flag;
            }

            return(true);
        }