A cross-platform UI framework for .NET
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

53 lines
1.4 KiB

using System;
using System.IO;
using System.Reflection;
using Avalonia.Metadata;
namespace Avalonia.Platform.Internal;
internal interface IAssetDescriptor
{
Stream GetStream();
Assembly Assembly { get; }
}
internal class AssemblyResourceDescriptor : IAssetDescriptor
{
private readonly Assembly _asm;
private readonly string _name;
public AssemblyResourceDescriptor(Assembly asm, string name)
{
_asm = asm;
_name = name;
}
public Stream GetStream()
{
var s = _asm.GetManifestResourceStream(_name);
return s ?? throw new InvalidOperationException($"Could not find manifest resource stream '{_name}',");
}
public Assembly Assembly => _asm;
}
internal class AvaloniaResourceDescriptor : IAssetDescriptor
{
private readonly int _offset;
private readonly int _length;
public Assembly Assembly { get; }
public AvaloniaResourceDescriptor(Assembly asm, int offset, int length)
{
_offset = offset;
_length = length;
Assembly = asm;
}
public Stream GetStream()
{
var s = Assembly.GetManifestResourceStream(Constants.AvaloniaResourceName) ??
throw new InvalidOperationException($"Could not find manifest resource stream '{Constants.AvaloniaResourceName}',");
return new SlicedStream(s, _offset, _length);
}
}