private void SetArg(FuncArg arg, IList <ArgValue> funcArgs, IEventArgs args) { ArgValue fa = GetArgValue(arg, funcArgs, args); if (fa != null) { IPara para = ParaUtil.GetPara(arg.GetType()); if (para != null) { try { IPara old = new ParaExp(fa.GetValue()).GetSourcePara(args); if (old != null) { if (old.GetValue() != null) { para = para.Initial("=", old.GetValue().ToString()); } else { para = para.Initial("=", string.Empty); } } else { para = para.Initial("=", FreeUtil.ReplaceNumber(fa.GetValue(), args)); } } catch (Exception) { para = para.Initial("=", FreeUtil.ReplaceNumber(fa.GetValue(), args)); } para.SetName("arg_" + arg.GetName()); args.GetDefault().GetParameters().TempUse(para); IPara p = (IPara)para.Borrow(); p.SetName(arg.GetName()); if (para.GetValue() != null) { p.SetValue("=", para); } args.GetDefault().GetParameters().TempUse(p); FreeLog.FuncArg(p.ToString()); } else { // 非简单变量 ((BaseEventArgs)args).TempUse(arg.GetName(), args.GetUnit(fa.GetValue())); } } }
private string Replace(IEventArgs args, bool once) { if (!var) { return(text); } else { IList <FreeUtil.PosIndex> list = GetPos(text, '{', '}'); if (list.Count == 0 || once) { IPara pa = new ParaExp(text).GetSourcePara(args); if (pa != null) { object va = pa.GetValue(); if (va != null) { return(va.ToString()); } } string v = HandleSpecial(text, args); if (v != null) { return(v); } StringBuilder sb = new StringBuilder(); sb.Append(VAR_START); sb.Append(text); sb.Append(VAR_END); return(sb.ToString()); } else { IList <FreeUtil.VarText> subs = ToVarText(text); StringBuilder sb = new StringBuilder(); foreach (FreeUtil.VarText vt in subs) { sb.Append(vt.Replace(args, false)); } FreeUtil.VarText newVt = new FreeUtil.VarText(sb.ToString(), true); return(newVt.Replace(args, true)); } } }
// 只有一层的变量,速度快 private static string ReplaceOneLevelVar(string message, IEventArgs args) { string nv = message; string[] vs = GetVars(message); if (vs.Length > 0) { string temp = message; foreach (string v in vs) { IPara pa = new ParaExp(v).GetSourcePara(args); if (pa != null) { object va = pa.GetValue(); if (va != null) { temp = temp.Replace(VAR_START + v + VAR_END, va.ToString()); } } } nv = temp; } return(nv); }