DotNext by .NET Foundation and Contributors

<PackageReference Include="DotNext" Version="4.0.0-beta.2" />

 ResourceEntry

public struct ResourceEntry
Represents resource entry.
using System; using System.Globalization; using System.IO; using System.Resources; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace DotNext.Resources { [StructLayout(LayoutKind.Auto)] [System.Runtime.CompilerServices.NullableContext(1)] [System.Runtime.CompilerServices.Nullable(0)] public readonly struct ResourceEntry { public string Name { get; } public ResourceManager Manager { get; } internal ResourceEntry(ResourceManager manager, string name) { if (manager == null) throw new ArgumentNullException("manager"); Manager = manager; if (name == null) throw new ArgumentNullException("name"); Name = name; } public string AsString([System.Runtime.CompilerServices.Nullable(2)] CultureInfo culture = null) { string string = Manager.GetString(Name, culture ?? CultureInfo.CurrentUICulture); if (string == null) throw new InvalidOperationException(ExceptionMessages.ResourceEntryIsNull(Name)); return string; } public string Format([System.Runtime.CompilerServices.Nullable(new byte[] { 1, 2 })] params object[] args) { CultureInfo currentUICulture = CultureInfo.CurrentUICulture; return string.Format(currentUICulture, AsString(currentUICulture), args); } public Stream AsStream([System.Runtime.CompilerServices.Nullable(2)] CultureInfo culture = null) { UnmanagedMemoryStream stream = Manager.GetStream(Name, culture ?? CultureInfo.CurrentUICulture); if (stream == null) throw new InvalidOperationException(ExceptionMessages.ResourceEntryIsNull(Name)); return stream; } [System.Runtime.CompilerServices.NullableContext(2)] [return: System.Runtime.CompilerServices.Nullable(1)] public T As<T>(CultureInfo culture = null) { object object = Manager.GetObject(Name, culture); if (!(object is T)) throw new InvalidOperationException(); return (T)object; } public static explicit operator string([In] [IsReadOnly] ref ResourceEntry entry) { return entry.AsString(null); } public static explicit operator Stream([In] [IsReadOnly] ref ResourceEntry entry) { return entry.AsStream(null); } } }