Example #1
0
        private void FindSaveFields()
        {
#if DEBUG
            Stopwatch sw = new Stopwatch();
            sw.Start();
#endif
            Type[] types = Assembly.GetAssembly(typeof(Storage)).GetTypes();
            foreach (var type in types)
            {
                FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public);
                foreach (var field in fields)
                {
                    Saved save = field.GetCustomAttribute <Saved>();
                    if (save != null)
                    {
                        save.type  = type;
                        save.field = field;

                        this.RegisterField(save);
                    }
                }
            }
#if DEBUG
            sw.Stop();
            if (sw.ElapsedMilliseconds > 10)
            {
                // Dear future-self,
                // If this breakpoint hit, you might want to reconsider the above code.
                Debugger.Break();
            }
#endif
        }
Example #2
0
 public void Add(Saved save)
 {
     this.Add(new Entry(
                  save.type.FullName,
                  save.name,
                  save.version,
                  save.field.GetValue(null)
                  ));
 }
Example #3
0
        private void RegisterField(Saved save)
        {
            save.name = save.name ?? save.field.Name;

            this.saves.Add(save);

            var typeFieldPair = Tuple.Create <string, string>(save.type.FullName, save.name);

            this.savesMap.Add(typeFieldPair, save);

            if (save.defaultValue != null)
            {
                save.field.SetValue(null, save.defaultValue);
            }
        }