internal class FinderAttribute : Attribute {
public string Path { get; init; }
public string Note { get; init; }
}
internal static class FinderHelper {
private static Dictionary<string, Type> _pathCache = new();
public static void FillCache() {
var finders = Assembly.GetExecutingAssembly().GetTypes().SelectMany(t => t.GetMethods(BindingFlags.Static | BindingFlags.NonPublic)).Where(m => m.GetCustomAttribute<FinderAttribute>() != null);
foreach (var finder in finders) {
var attr = finder.GetCustomAttribute<FinderAttribute>();
_pathCache[attr.Path] = (Type)finder.Invoke(null, []);
}
}
public static Type FindTypeForPath(string path) => ...;
[FinderAttribute(Path = "Path1/Path2/", Note = "...")]
private static Type Find1() {
// do logic to find the Type for path 1 in the assembly...
}
[FinderAttribute(Path = "Path1/Path3/", Note = "...")]
private static Type Find2() {
// do logic to find the Type for path 2 in the assembly...
}
}
internal class FinderAttribute : Attribute {
public string Path { get; init; }
public string Note { get; init; }
}
internal static class FinderHelper {
private static Dictionary<string, Type> _pathCache = new();
public static void FillCache() {
var finders = Assembly.GetExecutingAssembly().GetTypes().SelectMany(t => t.GetMethods(BindingFlags.Static | BindingFlags.NonPublic)).Where(m => m.GetCustomAttribute<FinderAttribute>() != null);
foreach (var finder in finders) {
var attr = finder.GetCustomAttribute<FinderAttribute>();
_pathCache[attr.Path] = (Type)finder.Invoke(null, []);
}
}
public static Type FindTypeForPath(string path) => ...;
[FinderAttribute(Path = "Path1/Path2/", Note = "...")]
private static Type Find1() {
// do logic to find the Type for path 1 in the assembly...
}
[FinderAttribute(Path = "Path1/Path3/", Note = "...")]
private static Type Find2() {
// do logic to find the Type for path 2 in the assembly...
}
}