/// <summary> /// Extracts interface types with specified filter from assembly. /// </summary> public static List <Type> GetInterfaces(Assembly assembly, IEnumerable <string> filters, IEnumerable <Type> dataTypes) { Regex nameFilter = CreateTypeNameFilter(filters); var interfaces = ActivatorUtil.EnumerateTypes(assembly).Where(t => t.IsInterface) .Where(t => nameFilter == null || nameFilter.IsMatch(t.FullName)) .ToList(); HashSet <Type> dataInterfaces = new HashSet <Type>(); foreach (Type type in dataTypes) { foreach (Type interfaceType in interfaces) { // Interface should be assignable from data type bool isAssignableFromData = interfaceType.IsAssignableFrom(type); // Skip RecordFor<> interfaces bool isAssignableFromRecord = interfaceType.IsAssignableFrom(typeof(TypedRecord <,>)); if (isAssignableFromData && !isAssignableFromRecord) { dataInterfaces.Add(interfaceType); } } } return(dataInterfaces.ToList()); }
/// <summary> /// Extracts enum types with specified filter from assembly. /// </summary> public static List <Type> GetEnums(Assembly assembly, IEnumerable <string> filters) { Regex nameFilter = CreateTypeNameFilter(filters); return(ActivatorUtil.EnumerateTypes(assembly) // Get all Data successors .Where(t => t.IsSubclassOf(typeof(Enum))) // Filter using user input or skip if none .Where(t => nameFilter == null || nameFilter.IsMatch(t.FullName)) .ToList()); }
/// <summary> /// Extracts data types with specified filter from assembly. /// </summary> public static List <Type> GetTypes(Assembly assembly, IEnumerable <string> filters) { Regex nameFilter = CreateTypeNameFilter(filters); bool IsKeyType(Type t) => t.BaseType.IsGenericType && (t.BaseType.GetGenericTypeDefinition() == typeof(TypedKey <,>)); return(ActivatorUtil.EnumerateTypes(assembly) // Get all Data successors .Where(t => t.IsSubclassOf(typeof(Data))) // Filter using user input or skip if none .Where(t => nameFilter == null || nameFilter.IsMatch(t.FullName)) // Skip key and basic classes .Where(t => !BasicTypes.Contains(t) && !IsKeyType(t)).ToList()); }