/// <summary> /// Allocates new or overrides existing <see cref="ModuleIdentity"/> this <see cref="ModuleReference"/> references. /// </summary> public void Reallocate() { _module = ModuleIdentity.GetModule(EnumValue); if (_onAllocate is not null) { _module.SetPackage(_onAllocate); } }
/// <summary> /// Returns a collection of <see cref="TypeIdentity"/>s representing all enabled Durian <see cref="Type"/>s for the specified <paramref name="assembly"/> that are part of any of the provided <paramref name="modules"/>. /// </summary> /// <param name="assembly"><see cref="Assembly"/> to get the enabled Durian <see cref="Type"/>s of.</param> /// <param name="modules">Array of <see cref="DurianModule"/>s to pick the <see cref="TypeIdentity"/>s from.</param> /// <exception cref="ArgumentNullException"><paramref name="assembly"/> is <see langword="null"/>.</exception> /// <exception cref = "InvalidOperationException" > Unknown <see cref="DurianModule"/> value detected. -or- <see cref = "DurianModule.None" /> is not a valid Durian module.</exception> public static IEnumerable <TypeIdentity> GetEnabledTypes(this Assembly assembly, params DurianModule[]?modules) { if (assembly is null) { throw new ArgumentNullException(nameof(assembly)); } if (modules is null || modules.Length == 0) { return(Array.Empty <TypeIdentity>()); } foreach (DurianModule module in modules) { ModuleIdentity.EnsureIsValidModuleEnum(module); } EnableModuleAttribute[] attributes = assembly.GetCustomAttributes <EnableModuleAttribute>().ToArray(); if (attributes.Length == 0) { return(Array.Empty <TypeIdentity>()); } return(Yield()); IEnumerable <TypeIdentity> Yield() { foreach (DurianModule module in modules) { if (IsEnabled_Internal(attributes, module)) { ModuleIdentity identity = ModuleIdentity.GetModule(module); foreach (TypeIdentity t in identity.Types) { yield return(t); } } } } }
/// <summary> /// Converts a collection of <see cref="DurianModule"/>s into an array of <see cref="ModuleIdentity"/>s. /// </summary> /// <param name="modules">A collection of <see cref="DurianModule"/>s to convert.</param> /// <exception cref="ArgumentNullException"><paramref name="modules"/> is <see langword="null"/>.</exception> /// <exception cref="InvalidOperationException">Unknown <see cref="DurianModule"/> value detected.</exception> public static ModuleIdentity[] ToIdentities(IEnumerable <DurianModule> modules) { if (modules is null) { throw new ArgumentNullException(nameof(modules)); } DurianModule[] array = modules.ToArray(); if (array.Length == 0) { return(Array.Empty <ModuleIdentity>()); } ModuleIdentity[] identities = new ModuleIdentity[array.Length]; for (int i = 0; i < identities.Length; i++) { identities[i] = ModuleIdentity.GetModule(array[i]); } return(identities); }