Class AssemblyDecoratorExtensions
- Namespace
- Cuemon.Reflection
- Assembly
- Cuemon.Core.dll
Extension methods for the Assembly class hidden behind the IDecorator<T> interface.
public static class AssemblyDecoratorExtensions
- Inheritance
-
AssemblyDecoratorExtensions
Examples
AssemblyDecoratorExtensions provides extension methods on Decorator.Enclose for inspecting assembly metadata, loading embedded resources, and filtering types. This example wraps the entry assembly and calls IsDebugBuild, GetAssemblyVersion, GetFileVersion, and GetProductVersion to retrieve version information. It also demonstrates GetTypes with optional namespace and interface filters, and GetManifestResources with various match modes including ContainsName, Extension, and Name. Console output displays each version string, boolean flags, and resource character counts.
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using Cuemon;
using Cuemon.Reflection;
namespace MyApp.Examples;
public class Example
{
public void Run()
{
// Get the entry assembly to inspect
var assembly = Assembly.GetExecutingAssembly();
var decorator = Decorator.Enclose(assembly);
// Check if it's a debug build
bool isDebug = decorator.IsDebugBuild(); // true in Debug config, false in Release
// Get version information
var asmVersion = decorator.GetAssemblyVersion(); // from AssemblyVersionAttribute
var fileVersion = decorator.GetFileVersion(); // from AssemblyFileVersionAttribute
var productVersion = decorator.GetProductVersion(); // from AssemblyInformationalVersionAttribute
Console.WriteLine($"Assembly version: {asmVersion}");
Console.WriteLine($"File version: {fileVersion}");
Console.WriteLine($"Product version: {productVersion}");
// Get types from the assembly, optionally filtered
var allTypes = decorator.GetTypes(); // all types in the assembly
var filteredByNamespace = decorator.GetTypes(namespaceFilter: "Cuemon.Reflection"); // types in a specific namespace
var filteredByInterface = decorator.GetTypes(typeFilter: typeof(IDisposable)); // types implementing IDisposable
// Load embedded manifest resources (partial name match)
var resources = decorator.GetManifestResources("config", ManifestResourceMatch.ContainsName);
foreach (var resource in resources)
{
using var reader = new StreamReader(resource.Value);
string content = reader.ReadToEnd();
Console.WriteLine($"Resource '{resource.Key}': {content.Length} chars");
// Find resources by file extension
var jsonFiles = decorator.GetManifestResources(".json", ManifestResourceMatch.Extension);
// Get a resource by exact name
var singleResource = decorator.GetManifestResources("MyApp.Resources.data.xml", ManifestResourceMatch.Name);
}}
}
Methods
GetAssemblyVersion(IDecorator<Assembly>)
Returns a VersionResult that represents the AssemblyVersionAttribute of the underlying Assembly of the decorator.
public static VersionResult GetAssemblyVersion(this IDecorator<Assembly> decorator)
Parameters
decoratorIDecorator<Assembly>The IDecorator<T> to extend.
Returns
- VersionResult
A VersionResult that represents the underlying Assembly of the
decorator.
Exceptions
- ArgumentNullException
decoratorcannot be null.
GetFileVersion(IDecorator<Assembly>)
Returns a VersionResult that represents the AssemblyFileVersionAttribute of the underlying Assembly of the decorator.
public static VersionResult GetFileVersion(this IDecorator<Assembly> decorator)
Parameters
decoratorIDecorator<Assembly>The IDecorator<T> to extend.
Returns
- VersionResult
A VersionResult that represents the file version of the underlying Assembly of the
decorator; null if no AssemblyFileVersionAttribute could be retrieved.
Exceptions
- ArgumentNullException
decoratorcannot be null.
GetManifestResources(IDecorator<Assembly>, string, ManifestResourceMatch)
Loads the embedded resources from the underlying Assembly of the decorator.
public static IDictionary<string, Stream> GetManifestResources(this IDecorator<Assembly> decorator, string name, ManifestResourceMatch match = ManifestResourceMatch.Name)
Parameters
decoratorIDecorator<Assembly>The IDecorator<T> to extend.
namestringThe case-sensitive name of the resource being requested.
matchManifestResourceMatchThe ruleset that defines the match to apply.
Returns
- IDictionary<string, Stream>
An IDictionary<TKey, TValue> that contains the result of
match.
Remarks
The result returned can have null values if no resources were specified during compilation or if the resource is not visible to the caller.
Exceptions
- ArgumentNullException
decoratorcannot be null -or-namecannot be null.- ArgumentException
namecannot be empty or consist only of white-space characters.- InvalidEnumArgumentException
matchwas not in the range of valid values.
- See Also
GetProductVersion(IDecorator<Assembly>)
Returns a VersionResult that represents the AssemblyInformationalVersionAttribute of the underlying Assembly of the decorator.
public static VersionResult GetProductVersion(this IDecorator<Assembly> decorator)
Parameters
decoratorIDecorator<Assembly>The IDecorator<T> to extend.
Returns
- VersionResult
A VersionResult that represents the product version of the underlying Assembly of the
decorator; null if no AssemblyInformationalVersionAttribute could be retrieved.
Exceptions
- ArgumentNullException
decoratorcannot be null.
GetTypes(IDecorator<Assembly>, string, Type)
Gets the types contained within the underlying Assembly of this instance.
public static IEnumerable<Type> GetTypes(this IDecorator<Assembly> decorator, string namespaceFilter = null, Type typeFilter = null)
Parameters
decoratorIDecorator<Assembly>The IDecorator<T> to extend.
namespaceFilterstringThe filter to limit the types by namespace.
typeFilterTypeThe filter to limit the types by a specific type.
Returns
- IEnumerable<Type>
A sequence of Type elements, matching the applied filters, from the underlying Assembly of this instance.
Exceptions
- ArgumentNullException
decoratorcannot be null.
IsDebugBuild(IDecorator<Assembly>)
Determines whether the underlying Assembly of the decorator is a debug build.
public static bool IsDebugBuild(this IDecorator<Assembly> decorator)
Parameters
decoratorIDecorator<Assembly>The IDecorator<T> to extend.
Returns
Exceptions
- ArgumentNullException
decoratorcannot be null.