Command.Registry.RegisterClass C# (CSharp) Méthode

RegisterClass() public méthode

Registers commands and factories from the supplied class. Commands must be tagged with the attribute Command to be locatable.
public RegisterClass ( Type t ) : void
t System.Type
Résultat void
        public void RegisterClass(Type t)
        {
            Factory factory;
            Command cmd;

            if(t.IsClass) {
                // Process class level attributes
                List<SettingAttribute> settings = new List<SettingAttribute>();
                foreach(var attr in t.GetCustomAttributes(typeof(SettingAttribute), false)) {
                    if(attr is DynamicSettingAttribute) {
                        // Verify that DynamicSettingAttributes are only used on IDynamicSettingsCollection
                        if(t.GetInterface("IDynamicSettingsCollection") == null) {
                            throw new ArgumentException(string.Format("A DynamicSettingAttribute has " +
                                        "been defined on class {0}, but this class does not implement " +
                                        "the IDynamicSettingsCollection interface", t.Name));
                        }
                    }
                    settings.Add((SettingAttribute)attr);
                }
                // Attributes are returned in random order, so sort by preferred order
                settings.Sort((a, b) => (a.SortKey).CompareTo(b.SortKey));
                _settings[t] = settings;

                // Process members of class
                foreach(var mi in t.GetMembers(BindingFlags.Public|BindingFlags.Instance|BindingFlags.DeclaredOnly)) {
                    cmd = null;
                    factory = null;
                    foreach(var attr in mi.GetCustomAttributes(false)) {
                        if(attr is CommandAttribute) {
                            cmd = new Command(t, mi as MethodInfo, attr as CommandAttribute);
                            Add(cmd);
                        }
                        if(attr is FactoryAttribute) {
                            factory = new Factory(mi, attr as FactoryAttribute);
                            Add(factory);
                        }
                    }
                    if(cmd != null && factory != null) {
                        cmd._factory = factory;
                        factory._command = cmd;
                    }
                }
            }
        }