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)); } } } }
public override void DoAction(IEventArgs args) { object target = GetTarget(args); if (fields != null && values != null) { string[] fs = StringUtil.Split(fields, ","); string[] vs = StringUtil.Split(values, ","); if (fs.Length == vs.Length) { for (int i = 0; i < fs.Length; i++) { try { string fName = fs[i].Trim(); FieldInfo f = ReflectionCache.GetField(target, fName); string type = f.GetType().Name.ToLower(); IPara p = null; string[] ss = StringUtil.Split(vs[i].Trim(), "."); if (ss.Length == 2) { if (args.GetUnit(ss[0].Trim()) != null) { p = args.GetUnit(ss[0].Trim()).GetParameters().Get(ss[1].Trim()); } } else { if (ss.Length == 1) { p = args.GetDefault().GetParameters().Get(ss[0].Trim()); } } object v = null; if (p != null) { v = p.GetValue(); } if ("long".Equals(type)) { if (v == null) { v = long.Parse(vs[i].Trim()); } } else { if ("int".Equals(type)) { if (v == null) { v = int.Parse(vs[i].Trim()); } } else { if ("float".Equals(type)) { if (v == null) { v = float.Parse(vs[i].Trim()); } } else { if ("double".Equals(type)) { if (v == null) { v = double.Parse(vs[i].Trim()); } } else { if ("string".Equals(type)) { if (v == null) { v = vs[i].Trim().ToString(); } } else { if ("boolean".Equals(type)) { if (v == null) { v = bool.Parse(vs[i].Trim()); } } else { throw new GameConfigExpception(fName + "'s type '" + type + "' is not supported."); } } } } } } SetValue(target, f, v); System.Console.Out.WriteLine(target.GetType().FullName + "'s " + fName + " -> " + v); } catch (Exception e) { throw new GameConfigExpception("set " + fields + " to " + values + " failed at " + target.GetType().FullName + "\n" + ExceptionUtil.GetExceptionContent(e)); } } } } }