Table of Contents

Class AssemblyExtensions

Namespace
Cuemon.Extensions.Reflection
Assembly
Cuemon.Extensions.Reflection.dll

Extension methods for the Assembly class.

public static class AssemblyExtensions
Inheritance
AssemblyExtensions

Examples

AssemblyExtensions provides extension methods for Assembly to retrieve version information and debug-build status. This example obtains the entry assembly and calls GetAssemblyVersion, GetFileVersion, and GetProductVersion to read version attributes, then checks HasAlphanumericVersion and IsSemanticVersion() on the returned SourceVersion objects. It also calls IsDebugBuild() to determine whether the assembly was compiled in Debug configuration. Console output displays each version string (e.g., 1.0.0.0), whether it has alphanumeric or semantic version characteristics, and the debug-build flag.

using System;
using System.Reflection;
using Cuemon.Extensions.Reflection;

namespace MyApp.Reflection
{
    public class AssemblyExtensionsExample
    {
        public void Demonstrate()
        {
            var assembly = typeof(AssemblyExtensionsExample).Assembly;

            // Get the assembly version (from AssemblyVersionAttribute)
            var assemblyVersion = assembly.GetAssemblyVersion();
            Console.WriteLine($"Assembly version: {assemblyVersion}"); // e.g., "1.0.0.0"
            Console.WriteLine($"Has alphanumeric version: {assemblyVersion.HasAlphanumericVersion}"); // False
            Console.WriteLine($"Is semantic version: {assemblyVersion.IsSemanticVersion()}"); // False

            // Get the file version (from AssemblyFileVersionAttribute)
            var fileVersion = assembly.GetFileVersion();
            Console.WriteLine($"File version: {fileVersion}"); // e.g., "1.0.0.0"

            // Get the product version (from AssemblyInformationalVersionAttribute)
            var productVersion = assembly.GetProductVersion();
            Console.WriteLine($"Product version: {productVersion}"); // e.g., "1.0.0"
            Console.WriteLine($"Has alphanumeric version: {productVersion.HasAlphanumericVersion}"); // True (usually)
            Console.WriteLine($"Is semantic version: {productVersion.IsSemanticVersion()}"); // True

            // Check if the assembly is a debug build
            var isDebug = assembly.IsDebugBuild();
            Console.WriteLine($"Is debug build: {isDebug}"); // True in Debug, False in Release

}}
}

Methods

GetAssemblyVersion(Assembly)

Returns a VersionResult that represents the version number of the specified assembly.

public static VersionResult GetAssemblyVersion(this Assembly assembly)

Parameters

assembly Assembly

The assembly to resolve a Version from.

Returns

VersionResult

A VersionResult that represents the version number of the specified assembly.

GetFileVersion(Assembly)

Returns a VersionResult that represents the file version number of the specified assembly.

public static VersionResult GetFileVersion(this Assembly assembly)

Parameters

assembly Assembly

The assembly to resolve a Version from.

Returns

VersionResult

A VersionResult that represents the file version number of the specified assembly.

Exceptions

ArgumentNullException

assembly is null.

GetProductVersion(Assembly)

Returns a VersionResult that represents the version of the product this assembly is distributed with.

public static VersionResult GetProductVersion(this Assembly assembly)

Parameters

assembly Assembly

The assembly to resolve a Version from.

Returns

VersionResult

A VersionResult that represents the version of the product this assembly is distributed with.

Exceptions

ArgumentNullException

assembly is null.

IsDebugBuild(Assembly)

Determines whether the specified assembly is a debug build.

public static bool IsDebugBuild(this Assembly assembly)

Parameters

assembly Assembly

The assembly to parse and determine whether it is a debug build or not.

Returns

bool

true if the specified assembly is a debug build; otherwise, false.