2026-04-18 06:04:39 +01:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
|
|
namespace GameCult.Caching
|
|
|
|
|
{
|
2026-05-08 01:13:15 +01:00
|
|
|
internal static class ReflectionExtensions
|
2026-04-18 06:04:39 +01:00
|
|
|
{
|
2026-05-08 01:13:15 +01:00
|
|
|
public static IEnumerable<Type> GetAttributedDocumentTypes()
|
2026-04-18 06:04:39 +01:00
|
|
|
{
|
2026-05-08 01:13:15 +01:00
|
|
|
return AppDomain.CurrentDomain.GetAssemblies()
|
|
|
|
|
.Where(assembly => !assembly.IsDynamic)
|
|
|
|
|
.SelectMany(SafeGetTypes)
|
|
|
|
|
.Where(type => type is { IsAbstract: false, IsInterface: false })
|
|
|
|
|
.Where(type => type.GetCustomAttribute<CultDocumentAttribute>() != null);
|
2026-04-18 06:04:39 +01:00
|
|
|
}
|
|
|
|
|
|
2026-05-08 01:13:15 +01:00
|
|
|
public static IEnumerable<Type> SafeGetTypes(Assembly assembly)
|
2026-04-18 06:04:39 +01:00
|
|
|
{
|
2026-05-08 01:13:15 +01:00
|
|
|
try
|
2026-04-18 06:04:39 +01:00
|
|
|
{
|
2026-05-08 01:13:15 +01:00
|
|
|
return assembly.GetTypes();
|
2026-04-18 06:04:39 +01:00
|
|
|
}
|
2026-05-08 01:13:15 +01:00
|
|
|
catch (ReflectionTypeLoadException ex)
|
2026-04-18 06:04:39 +01:00
|
|
|
{
|
2026-05-08 01:13:15 +01:00
|
|
|
return ex.Types.Where(type => type != null)!;
|
2026-04-18 06:04:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-04-18 13:01:24 +01:00
|
|
|
}
|