Class AssemblyExtensions
- Namespace
- Plugin.BaseTypeExtensions
- Assembly
- Plugin.BaseTypeExtensions.dll
Provides extension methods for Assembly operations, including manifest resource extraction.
public static class AssemblyExtensions
- Inheritance
-
AssemblyExtensions
- Inherited Members
Properties
CacheDirectory
Gets or sets the cache directory used for resource extraction.
Overridden in the Maui project to use FileSystem.CacheDirectory
.
In unit tests, it uses GetTempPath() to ensure compatibility.
public static string CacheDirectory { get; set; }
Property Value
Methods
MoveManifestResourceToCache(Assembly, string, string?, FileAlreadyExistsBehavior)
Extracts a manifest resource from an assembly and saves it to the cache directory.
public static FileInfo MoveManifestResourceToCache(this Assembly assembly, string manifestResourceName, string? filename = null, AssemblyExtensions.FileAlreadyExistsBehavior fileAlreadyExistsBehavior = FileAlreadyExistsBehavior.Fail)
Parameters
assembly
AssemblyThe assembly containing the manifest resource.
manifestResourceName
stringThe name of the manifest resource to extract.
filename
stringThe filename for the extracted resource. If null, a random filename will be generated.
fileAlreadyExistsBehavior
AssemblyExtensions.FileAlreadyExistsBehaviorBehavior when the target file already exists.
Returns
Exceptions
- ArgumentNullException
Thrown when required parameters are null.
- ArgumentException
Thrown when manifestResourceName is empty or whitespace.
- DirectoryNotFoundException
Thrown when the cache directory cannot be created or accessed.
- FileNotFoundException
Thrown when the manifest resource cannot be found.
- IOException
Thrown when file operations fail or when fileAlreadyExistsBehavior is Fail and file exists.
MoveManifestResourceToCacheAsync(Assembly, string, string?, FileAlreadyExistsBehavior, CancellationToken)
Extracts a manifest resource from an assembly and saves it to the cache directory asynchronously.
public static Task<FileInfo> MoveManifestResourceToCacheAsync(this Assembly assembly, string manifestResourceName, string? filename = null, AssemblyExtensions.FileAlreadyExistsBehavior fileAlreadyExistsBehavior = FileAlreadyExistsBehavior.Fail, CancellationToken cancellationToken = default)
Parameters
assembly
AssemblyThe assembly containing the manifest resource.
manifestResourceName
stringThe name of the manifest resource to extract.
filename
stringThe filename for the extracted resource. If null, a random filename will be generated.
fileAlreadyExistsBehavior
AssemblyExtensions.FileAlreadyExistsBehaviorBehavior when the target file already exists.
cancellationToken
CancellationTokenA token to cancel the operation.
Returns
- Task<FileInfo>
A Task<TResult> representing the asynchronous operation that returns a FileInfo object for the extracted file.
Exceptions
- ArgumentNullException
Thrown when required parameters are null.
- ArgumentException
Thrown when manifestResourceName is empty or whitespace.
- DirectoryNotFoundException
Thrown when the cache directory cannot be created or accessed.
- FileNotFoundException
Thrown when the manifest resource cannot be found.
- IOException
Thrown when file operations fail or when fileAlreadyExistsBehavior is Fail and file exists.
- OperationCanceledException
Thrown when the operation is cancelled via the cancellation token.
MoveManifestResourceToDirectory(Assembly, string, string, string?, FileAlreadyExistsBehavior)
Extracts a manifest resource from an assembly and saves it to a specified directory.
public static FileInfo MoveManifestResourceToDirectory(this Assembly assembly, string manifestResourceName, string targetDirectory, string? filename = null, AssemblyExtensions.FileAlreadyExistsBehavior fileAlreadyExistsBehavior = FileAlreadyExistsBehavior.Fail)
Parameters
assembly
AssemblyThe assembly containing the manifest resource.
manifestResourceName
stringThe name of the manifest resource to extract.
targetDirectory
stringThe directory where the resource should be saved.
filename
stringThe filename for the extracted resource. If null, a random filename will be generated.
fileAlreadyExistsBehavior
AssemblyExtensions.FileAlreadyExistsBehaviorBehavior when the target file already exists.
Returns
Exceptions
- ArgumentNullException
Thrown when required parameters are null.
- ArgumentException
Thrown when manifestResourceName is empty or whitespace.
- DirectoryNotFoundException
Thrown when the target directory cannot be created or accessed.
- FileNotFoundException
Thrown when the manifest resource cannot be found.
- IOException
Thrown when file operations fail or when fileAlreadyExistsBehavior is Fail and file exists.
MoveManifestResourceToDirectoryAsync(Assembly, string, string, string?, FileAlreadyExistsBehavior, CancellationToken)
Extracts a manifest resource from an assembly and saves it to a specified directory asynchronously.
public static Task<FileInfo> MoveManifestResourceToDirectoryAsync(this Assembly assembly, string manifestResourceName, string targetDirectory, string? filename = null, AssemblyExtensions.FileAlreadyExistsBehavior fileAlreadyExistsBehavior = FileAlreadyExistsBehavior.Fail, CancellationToken cancellationToken = default)
Parameters
assembly
AssemblyThe assembly containing the manifest resource.
manifestResourceName
stringThe name of the manifest resource to extract.
targetDirectory
stringThe directory where the resource should be saved.
filename
stringThe filename for the extracted resource. If null, a random filename will be generated.
fileAlreadyExistsBehavior
AssemblyExtensions.FileAlreadyExistsBehaviorBehavior when the target file already exists.
cancellationToken
CancellationTokenA token to cancel the operation.
Returns
- Task<FileInfo>
A Task<TResult> representing the asynchronous operation that returns a FileInfo object for the extracted file.
Exceptions
- ArgumentNullException
Thrown when required parameters are null.
- ArgumentException
Thrown when manifestResourceName is empty or whitespace.
- DirectoryNotFoundException
Thrown when the target directory cannot be created or accessed.
- FileNotFoundException
Thrown when the manifest resource cannot be found.
- IOException
Thrown when file operations fail or when fileAlreadyExistsBehavior is Fail and file exists.
- OperationCanceledException
Thrown when the operation is cancelled via the cancellation token.