using System.IO; using System.Reflection; using Microsoft.Toolkit.Diagnostics; #nullable enable namespace ComputeSharp.SwapChain.Uwp.Extensions; /// /// Helpers for the type. /// public static class AssemblyExtensions { /// /// Tries to read a from a specified file in the target . /// /// The target to read data from. /// The target filename to read from. /// The resulting text, if the read was successful. /// The contents of the specified file. 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.GetName().Name}.{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; } } }