Table of Contents

Class EmbeddedResourceAssetProvider

Namespace
VpnHood.Net.Toolkit.Assets
Assembly
VpnHood.Net.Toolkit.dll

Provides the assets an assembly carries as embedded resources, each named by the prefix followed by the asset path. They are in memory, so their streams can seek.

public class EmbeddedResourceAssetProvider : IAssetProvider
Inheritance
EmbeddedResourceAssetProvider
Implements
Inherited Members

Constructors

EmbeddedResourceAssetProvider(Assembly, string)

Provides the assets an assembly carries as embedded resources, each named by the prefix followed by the asset path. They are in memory, so their streams can seek.

public EmbeddedResourceAssetProvider(Assembly assembly, string resourcePrefix)

Parameters

assembly Assembly

The assembly.

resourcePrefix string

The prefix of the resources' names.

Methods

OpenReadAsync(string, CancellationToken)

Opens the asset at a path, such as fonts/text.ttf.

public Task<Stream> OpenReadAsync(string assetPath, CancellationToken cancellationToken)

Parameters

assetPath string

The asset's path.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<Stream>

A task whose result is a new stream, which the caller owns and disposes.

Remarks

It is asynchronous because a page in a browser fetches over the network and cannot wait. Read the stream forward: whether it can seek is the platform's answer, not a promise; a file can, an HTTP body and an Android asset cannot. A caller that needs more than one pass opens the asset again where it can, and copies it into memory only where it cannot, so the cost is paid where it is decided. A caller that only asks, such as a language falling back to another, takes TryOpenReadAsync, which gives null for an absent asset.

Exceptions

AssetNotFoundException

The provider classes the asset as absent; exactly this type, as a file it finds and cannot open is another failure.