using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using Vision.Core.Collections; namespace Vision.Core { public static class VisionAssembly { public static string Name = Assembly.GetEntryAssembly()?.GetName().Name; public static string Version = Assembly.GetEntryAssembly()?.GetName().Version.ToString(3); public static IEnumerable VisionAssemblies = AppDomain.CurrentDomain.GetAssemblies().Where(assembly => !assembly.GlobalAssemblyCache); public static IEnumerable VisionTypes = VisionAssemblies.SelectMany(assembly => assembly.GetTypes()); public static IEnumerable> GetMethodsWithAttribute() where TAttribute : Attribute { return VisionTypes .SelectMany(type => type.GetMethods()) .Select(method => new { Method = method, Attribute = Attribute.GetCustomAttribute(method, typeof(TAttribute), false) as TAttribute }).Where(param1 => param1.Attribute != null).Select(param1 => new Pair(param1.Attribute, param1.Method)); } public static IEnumerable GetTypes() => VisionTypes.Where(a => a == typeof(T)); public static IEnumerable GetTypesOfBase() => VisionTypes.Where(a => a.BaseType == typeof(T)); } }