コード例 #1
0
        public MCMGlobalSettingsContainer()
        {
            var settings = new List <GlobalSettings>();
            var allTypes = AppDomain.CurrentDomain
                           .GetAssemblies()
                           .Where(a => !a.IsDynamic)
                           // ignore v1 and v2 classes
                           .Where(a => !Path.GetFileNameWithoutExtension(a.Location).StartsWith("MBOptionScreen"))
                           .SelectMany(a => a.GetTypes())
                           .Where(t => t.IsClass && !t.IsAbstract)
                           .Where(t => t.GetConstructor(Type.EmptyTypes) != null)
                           .ToList();

            var mbOptionScreenSettings = allTypes
                                         .Where(t => ReflectionUtils.ImplementsOrImplementsEquivalent(t, typeof(GlobalSettings)))
                                         .Where(t => !ReflectionUtils.ImplementsOrImplementsEquivalent(t, typeof(EmptyGlobalSettings)))
                                         .Where(t => !ReflectionUtils.ImplementsOrImplementsEquivalent(t, typeof(IWrapper)))
                                         .Select(obj => BaseGlobalSettingsWrapper.Create(Activator.CreateInstance(obj)));

            settings.AddRange(mbOptionScreenSettings);

            foreach (var setting in settings)
            {
                RegisterSettings(setting);
            }
        }
コード例 #2
0
 public override BaseSettings?GetSettings(string id)
 {
     foreach (var settingsContainer in SettingsContainers)
     {
         if (settingsContainer.GetSettings(id) is {} settings)
         {
             return(settings is BaseSettings baseSettings ? baseSettings : BaseGlobalSettingsWrapper.Create(settings));
         }
     }
     return(null);
 }