Minor code refactoring
このコミットが含まれているのは:
1 親
cb9c0d9b7b
コミット
c06594c0d0
3ファイル変更
+59
-18
検索条件に一致するファイルはありません
@@ -0,0 +1,44 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace ComputeSharp.SwapChain.Uwp.Extensions;
|
||||
|
||||
/// <summary>
|
||||
/// Helpers for the <see cref="Assembly"/> type.
|
||||
/// </summary>
|
||||
public static class AssemblyExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Tries to read a <see cref="string"/> from a specified file in the target <see cref="Assembly"/>.
|
||||
/// </summary>
|
||||
/// <param name="assembly">The target <see cref="Assembly"/> to read data from.</param>
|
||||
/// <param name="filename">The target filename to read from.</param>
|
||||
/// <param name="text">The resulting text, if the read was successful.</param>
|
||||
/// <returns>The contents of the specified file.</returns>
|
||||
public static bool TryReadAllTextFromManifestFile(this Assembly assembly, string filename, out string? text)
|
||||
{
|
||||
Guard.IsNotNull(assembly, nameof(assembly));
|
||||
Guard.IsNotNull(filename, nameof(filename));
|
||||
|
||||
try
|
||||
{
|
||||
string manifestFilename = $"{assembly.FullName}.{filename.Replace('/', '.').Replace('\\', '.')}";
|
||||
|
||||
using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(manifestFilename);
|
||||
using StreamReader reader = new(stream);
|
||||
|
||||
text = reader.ReadToEnd().Trim();
|
||||
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
text = null;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする