Class EmbeddedResourceAssetProvider
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
Methods
OpenReadAsync(string, CancellationToken)
Opens the asset at a path, such as fonts/text.ttf.
public Task<Stream> OpenReadAsync(string assetPath, CancellationToken cancellationToken)
Parameters
assetPathstringThe asset's path.
cancellationTokenCancellationTokenThe token to monitor for cancellation requests.
Returns
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.