Exemple #1
0
 private void AddTo(string[] fields, IParable target, ParaList to)
 {
     foreach (string field in fields)
     {
         FieldPair fp = FieldPair.Parse(field)[0];
         ParaList  tp = target.GetParameters();
         if (tp.HasPara(fp.GetFrom()))
         {
             IPara para = tp.Get(fp.GetFrom());
             if (para != null)
             {
                 IPara clone = (IPara)para.Copy();
                 clone.SetName(fp.GetTo());
                 if (@override || !to.HasPara(fp.GetTo()))
                 {
                     to.AddPara(clone);
                 }
                 else
                 {
                     to.AddPara(clone);
                 }
             }
         }
     }
 }
        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));
                    }
                }
            }
        }