Beispiel #1
0
 public static void ApplyLang(object obj)
 {
     if (LangMap.TryGetValue(obj.GetType().Name, out var v))
     {
         ApplyLang(obj, (LangDic)v);
     }
 }
Beispiel #2
0
        private static void ApplyLang(object obj, LangDic dic)
        {
            var type = obj.GetType();

            foreach (var st in dic)
            {
                foreach (var fi in type.GetFields(BindingFlagAll))
                {
                    if (!dic.TryGetValue(fi.Name, out var dv))
                    {
                        continue;
                    }

                    if (dv is LangValue lv)
                    {
                        fi.SetValue(obj, lv.Value);
                    }
                    else
                    {
                        ApplyLang(fi.GetValue(obj), (LangDic)dv);
                        return;
                    }
                }

                foreach (var pi in type.GetProperties(BindingFlagAll))
                {
                    if (!dic.TryGetValue(pi.Name, out var dv))
                    {
                        continue;
                    }

                    if (dv is LangValue lv)
                    {
                        pi.SetValue(obj, lv.Value);
                    }
                    else
                    {
                        ApplyLang(pi.GetValue(obj), (LangDic)dv);
                        return;
                    }
                }
            }
        }