示例#1
0
        public override void DoAction(IEventArgs args)
        {
            UnitPara up   = UnitPara.Parse(FreeUtil.ReplaceVar(this.para, args))[0];
            IPara    para = up.GetPara(args);

            if (para != null)
            {
                double d = FreeUtil.ReplaceDouble(formula, args);
                if (para is IntPara)
                {
                    para.SetValue("=", new IntPara(string.Empty, (int)d));
                }
                if (para is FloatPara)
                {
                    para.SetValue("=", new FloatPara(string.Empty, (float)d));
                }
                if (para is DoublePara)
                {
                    para.SetValue("=", new DoublePara(string.Empty, d));
                }
                else
                {
                    IPara v = new DoublePara("v", d);
                    para.SetValue("=", v);
                }
            }
        }
        public override void DoAction(IEventArgs args)
        {
            ParaList target = GetTarget(args);
            object   source = GetSource(args);

            if (fields != null && source != null && target != null)
            {
                foreach (FieldPair fN in FieldPair.Parse(fields))
                {
                    string[] ffs = new string[2];
                    ffs[0] = fN.GetFrom();
                    ffs[1] = fN.GetTo();
                    try
                    {
                        FieldInfo    f    = ReflectionCache.GetField(source, ffs[0].Trim());
                        AbstractPara para = null;
                        string       type = f.GetType().Name.ToLower();
                        if ("long".Equals(type))
                        {
                            para = new LongPara(ffs[1].Trim());
                        }
                        if ("int".Equals(type))
                        {
                            para = new IntPara(ffs[1].Trim());
                        }
                        if ("float".Equals(type))
                        {
                            para = new FloatPara(ffs[1].Trim());
                        }
                        if ("double".Equals(type))
                        {
                            para = new DoublePara(ffs[1].Trim());
                        }
                        if ("string".Equals(type))
                        {
                            para = new StringPara(ffs[1].Trim());
                        }
                        if ("boolean".Equals(type))
                        {
                            para = new BoolPara(ffs[1].Trim());
                        }
                        if (para == null)
                        {
                            throw new GameConfigExpception(ffs[1].Trim() + "'s type '" + type + "' is not supported.");
                        }

                        para.SetValue(f.GetValue(source));

                        target.AddPara(para);
                    }
                    catch (Exception e)
                    {
                        throw new GameConfigExpception(fN + " is not a valid field.\n" + ExceptionUtil.GetExceptionContent(e));
                    }
                }
            }
        }
示例#3
0
        public static IPara GetPara(object obj, string field)
        {
            if (obj == null)
            {
                return(null);
            }
            FieldInfo    f    = GetField(obj, field);
            AbstractPara para = null;

            if (f != null)
            {
                string type = f.FieldType.Name;

                if (ParseUtility.IsInt64(type))
                {
                    para = new LongPara(field);
                }
                if (ParseUtility.IsInt32(type))
                {
                    para = new IntPara(field);
                }
                if (ParseUtility.IsSingle(type))
                {
                    para = new FloatPara(field);
                }
                if (ParseUtility.IsDouble(type))
                {
                    para = new DoublePara(field);
                }
                if (ParseUtility.IsString(type))
                {
                    para = new StringPara(field);
                }
                if (ParseUtility.IsBoolean(type))
                {
                    para = new BoolPara(field);
                }
                try
                {
                    if (para != null)
                    {
                        para.SetValue(f.GetValue(obj));
                    }
                }
                catch (Exception e)
                {
                    throw new GameConfigExpception(field + " is not a valid field.\n" + ExceptionUtil.GetExceptionContent(e));
                }
            }
            return(para);
        }
示例#4
0
        public static IPara GetPara(object obj, string field)
        {
            if (obj == null)
            {
                return(null);
            }
            FieldInfo    f    = GetField(obj, field);
            AbstractPara para = null;

            if (f != null)
            {
                string type = f.FieldType.Name.ToLower();
                if ("int64".Equals(type))
                {
                    para = new LongPara(field);
                }
                if ("int32".Equals(type))
                {
                    para = new IntPara(field);
                }
                if ("single".Equals(type))
                {
                    para = new FloatPara(field);
                }
                if ("double".Equals(type))
                {
                    para = new DoublePara(field);
                }
                if ("string".Equals(type))
                {
                    para = new StringPara(field);
                }
                if ("boolean".Equals(type))
                {
                    para = new BoolPara(field);
                }
                try
                {
                    if (para != null)
                    {
                        para.SetValue(f.GetValue(obj));
                    }
                }
                catch (Exception e)
                {
                    throw new GameConfigExpception(field + " is not a valid field.\n" + ExceptionUtil.GetExceptionContent(e));
                }
            }
            return(para);
        }