Skip to main content

IAssetLoader Interface

Definition​

Assembly:Avalonia.Base
Package:Avalonia

Loads assets compiled into the application binary.

public interface IAssetLoader

Methods​

NameDescription
ExistsChecks if an asset with the specified URI exists.
GetAssemblyExtracts assembly information from URI
GetAssetsGets all assets of a folder and subfolders that match specified uri.
InvalidateAssemblyCache (2 overloads)Removes all assemblies from the cache.
OpenOpens the asset with the requested URI.
OpenAndGetAssemblyOpens the asset with the requested URI and returns the asset stream and the assembly containing the asset.
SetDefaultAssemblyWe need a way to override the default assembly selected by the host platform because right now it is selecting the wrong one for PCL based Apps. The AssetLoader needs a refactor cause right now it lives in 3+ platforms which can all be loaded on Windows.

Exists Method​

Checks if an asset with the specified URI exists.

public bool Exists(Uri uri, Uri baseUri)

Parameters​

uri Uri

The URI.

baseUri Uri

A base URI to use if uri is relative.

Returns​

bool

True if the asset could be found; otherwise false.

GetAssembly Method​

Extracts assembly information from URI

public System.Reflection.Assembly GetAssembly(Uri uri, Uri baseUri)

Parameters​

uri Uri

The URI.

baseUri Uri

A base URI to use if uri is relative.

Returns​

System.Reflection.Assembly

Assembly associated with the Uri

GetAssets Method​

Gets all assets of a folder and subfolders that match specified uri.

public System.Collections.Generic.IEnumerable<Uri> GetAssets(Uri uri, Uri baseUri)

Parameters​

uri Uri

The URI.

baseUri Uri

The base URI.

Returns​

System.Collections.Generic.IEnumerable<Uri>

All matching assets as a tuple of the absolute path to the asset and the assembly containing the asset

InvalidateAssemblyCache overloads​

InvalidateAssemblyCache Method​

Removes all assemblies from the cache.

public void InvalidateAssemblyCache()

InvalidateAssemblyCache Method​

Removes the assembly from the cache.

public void InvalidateAssemblyCache(string name)
Parameters​

name string

The Assemblies.First().GetName().Name

Open Method​

Opens the asset with the requested URI.

public System.IO.Stream Open(Uri uri, Uri baseUri)

Parameters​

uri Uri

The URI.

baseUri Uri

A base URI to use if uri is relative.

Returns​

System.IO.Stream

A stream containing the asset contents.

Exceptions​

OpenAndGetAssembly Method​

Opens the asset with the requested URI and returns the asset stream and the assembly containing the asset.

public ValueTuple<System.IO.Stream, System.Reflection.Assembly> OpenAndGetAssembly(Uri uri, Uri baseUri)

Parameters​

uri Uri

The URI.

baseUri Uri

A base URI to use if uri is relative.

Returns​

ValueTuple<System.IO.Stream, System.Reflection.Assembly>

The stream containing the asset contents together with the assembly.

Exceptions​

SetDefaultAssembly Method​

We need a way to override the default assembly selected by the host platform because right now it is selecting the wrong one for PCL based Apps. The AssetLoader needs a refactor cause right now it lives in 3+ platforms which can all be loaded on Windows.

public void SetDefaultAssembly(System.Reflection.Assembly assembly)

Parameters​

assembly System.Reflection.Assembly