Some additions to ReflectionCache source generator
This commit is contained in:
parent
9224a4a81c
commit
0a4bbce3f2
|
@ -64,15 +64,19 @@ namespace BizHawk.SrcGen.ReflectionCache
|
|||
var src = $@"#nullable enable
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
{(nSpace == "BizHawk.Common" ? string.Empty : "\nusing BizHawk.Common;")}
|
||||
using BizHawk.Common.StringExtensions;
|
||||
|
||||
namespace {nSpace}
|
||||
{{
|
||||
public static class ReflectionCache
|
||||
{{
|
||||
private const string EMBED_PREFIX = ""{nSpace}."";
|
||||
|
||||
private static Type[]? _types = null;
|
||||
|
||||
private static readonly Assembly Asm = typeof({nSpace}.ReflectionCache).Assembly;
|
||||
|
@ -81,11 +85,19 @@ namespace {nSpace}
|
|||
|
||||
public static Type[] Types => _types ??= Asm.GetTypesWithoutLoadErrors().ToArray();
|
||||
|
||||
public static IEnumerable<string> EmbeddedResourceList(string extraPrefix)
|
||||
{{
|
||||
var fullPrefix = EMBED_PREFIX + extraPrefix;
|
||||
return Asm.GetManifestResourceNames().Where(s => s.StartsWith(fullPrefix)).Select(s => s.RemovePrefix(fullPrefix));
|
||||
}}
|
||||
|
||||
public static IEnumerable<string> EmbeddedResourceList()
|
||||
=> EmbeddedResourceList(string.Empty);
|
||||
|
||||
/// <exception cref=""ArgumentException"">not found</exception>
|
||||
public static Stream EmbeddedResourceStream(string embedPath)
|
||||
{{
|
||||
var fullPath = $""{nSpace}.{{embedPath}}"";
|
||||
var fullPath = EMBED_PREFIX + embedPath;
|
||||
return Asm.GetManifestResourceStream(fullPath) ?? throw new ArgumentException($""resource at {{fullPath}} not found"", nameof(embedPath));
|
||||
}}
|
||||
}}
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue