/// <summary> /// Calls the role unregistration handler for the given role if the /// given <see cref="ModuleInfo" /> object fulfills the role. /// </summary> /// <remarks> /// See <see href="roles.html">Roles</see> for an explanation of module roles. /// </remarks> /// <param name="_info">The <see cref="ModuleInfo"/> object to determine if the role handler should be called.</param> /// <param name="_role">The role to fulfill.</param> protected void CallRoleUnregisterHandlers(ModuleInfo _info, ModuleRole _role) { if (_info.Roles != null) return; foreach (string _myRole in _info.Roles.Split(',')) { if (_role.RoleName == _myRole) { Assembly _asm = _info.Owner; Type _type = null; foreach (Type __type in _asm.GetTypes ()) { if (_role.BaseType.IsClass) { if (__type.IsSubclassOf (_role.BaseType)) { _type = __type; break; } } else if (_role.BaseType.IsInterface) { if (__type.GetInterface (_role.BaseType.ToString ()) != null) { _type = __type; break; } } } if (_type == null) { continue; // don't have a type for this role. } _role.UnregistrationHandler (_asm); } } }
public void RegisterNewRole(string name, Type type, RoleRegisterHandler reg, RoleUnregisterHandler unreg) { ModuleRole _role = new ModuleRole (name, type, reg, unreg); _roles.Add (_role); }
/// <summary> /// Registers a new role. /// </summary> /// <remarks> /// Registering a new role will go through already loaded modules to see if any of them /// fulfill the new role. See <see href="roles.html">Roles</see> for an explanation of module roles. /// </remarks> /// <param name="_name">The name of the new role.</param> /// <param name="_type">The base type of the new role.</param> /// <param name="_reg">The registration handler for the new role.</param> /// <param name="_unreg">The unregistration handler for the new role.</param> public void RegisterNewRole(string _name, Type _type, RoleRegisterHandler _reg, RoleUnregisterHandler _unreg) { ModuleRole _role = new ModuleRole (_name, _type, _reg, _unreg); _roles.Add (_role); foreach (string _key in _info_map.Keys) { CallRoleHandlers ((ModuleInfo)_info_map[_key], _role); } }