Baubit.Reflection 2025.49.1

dotnet add package Baubit.Reflection --version 2025.49.1
                    
NuGet\Install-Package Baubit.Reflection -Version 2025.49.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Baubit.Reflection" Version="2025.49.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Baubit.Reflection" Version="2025.49.1" />
                    
Directory.Packages.props
<PackageReference Include="Baubit.Reflection" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Baubit.Reflection --version 2025.49.1
                    
#r "nuget: Baubit.Reflection, 2025.49.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Baubit.Reflection@2025.49.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Baubit.Reflection&version=2025.49.1
                    
Install as a Cake Addin
#tool nuget:?package=Baubit.Reflection&version=2025.49.1
                    
Install as a Cake Tool

Baubit.Reflection

CircleCI codecov<br/> NuGet .NET Standard 2.0<br/> License: MIT Known Vulnerabilities

A utility library for .NET that provides enhanced reflection capabilities with functional error handling using FluentResults. This library simplifies common reflection tasks such as assembly resolution, type resolution, and assembly-qualified name formatting.

Features

  • Assembly Management: Advanced assembly name parsing and resolution with version-aware comparison
  • Type Resolution: Safe type resolution with descriptive error handling
  • Assembly Name Formatting: Generate clean, simplified assembly-qualified type names (Baubit format)
  • Resource Reading: Read embedded resources from assemblies with error handling
  • Functional Error Handling: All operations return Result<T> types for safe error handling using FluentResults

Installation

Install the package via NuGet:

dotnet add package Baubit.Reflection

Or via the NuGet Package Manager:

Install-Package Baubit.Reflection

Usage

Assembly Name Resolution

Parse Assembly Names from Persistable Strings
using Baubit.Reflection;

// Parse assembly name from "Name/Version" format
var assemblyName = AssemblyExtensions.GetAssemblyNameFromPersistableString("MyAssembly/1.2.3.4");
// assemblyName.Name = "MyAssembly"
// assemblyName.Version = Version(1, 2, 3, 4)
Resolve Loaded Assemblies
using Baubit.Reflection;

var assemblyName = new AssemblyName("System.Runtime");
var assembly = assemblyName.TryResolveAssembly();

if (assembly != null)
{
    Console.WriteLine($"Found assembly: {assembly.FullName}");
}
Compare Assembly Names with Version-Aware Logic
using Baubit.Reflection;

var assembly1 = new AssemblyName { Name = "MyLib", Version = new Version(1, 2, 3, 4) };
var assembly2 = new AssemblyName { Name = "MyLib", Version = new Version(1, 2, 3) };

// Compares Major, Minor, Build; ignores Revision if one is undefined
bool isSame = assembly1.IsSameAs(assembly2); // true (revision difference ignored)

Type Resolution

Safely Resolve Types
using Baubit.Reflection;

var assemblyQualifiedName = "System.String, System.Private.CoreLib";
var result = TypeResolver.TryResolveType(assemblyQualifiedName);

if (result.IsSuccess)
{
    Type resolvedType = result.Value;
    Console.WriteLine($"Resolved type: {resolvedType.FullName}");
}
else
{
    // Check for specific error reasons
    var typeNotDefinedReason = result.Reasons.OfType<TypeNotDefined>().FirstOrDefault();
    Console.WriteLine($"Failed: {typeNotDefinedReason?.Message}");
}

Assembly-Qualified Name Formatting

Generate Clean Type Names (Baubit Format)
using Baubit.Reflection;

var type = typeof(Dictionary<string, List<int>>);
var result = type.GetBaubitFormattedAssemblyQualifiedName();

if (result.IsSuccess)
{
    // Returns type name without Version, Culture, PublicKeyToken
    Console.WriteLine(result.Value);
    // Example: System.Collections.Generic.Dictionary`2[[System.String],[System.Collections.Generic.List`1[[System.Int32]]]]
}

Read Embedded Resources

Read Assembly Resources Asynchronously
using Baubit.Reflection;

var assembly = Assembly.GetExecutingAssembly();
var result = await assembly.ReadResource("MyNamespace.EmbeddedFile.txt");

if (result.IsSuccess)
{
    string content = result.Value;
    Console.WriteLine($"Resource content: {content}");
}
else
{
    Console.WriteLine($"Failed to read resource: {result.Errors.First().Message}");
}

Create Instances using specific constructors

CreateInstance

Create type instances via reflection with Result error handling.

var result = typeof(MyService).CreateInstance<IMyService>(
    new[] { typeof(IConfiguration), typeof(ILogger) },
    new object[] { config, logger }
);
if (result.IsSuccess)
{
    var service = result.Value;
}

Stream Utilities

Read Streams as Strings
using Baubit.Reflection;

using var stream = new MemoryStream(Encoding.UTF8.GetBytes("Hello, World!"));
var result = await stream.ReadStringAsync();

if (result.IsSuccess)
{
    Console.WriteLine(result.Value); // "Hello, World!"
}

Key Classes and Methods

AssemblyExtensions

Method Description
GetAssemblyNameFromPersistableString(string) Parse assembly name from "Name/Version" format
TryResolveAssembly(this AssemblyName) Attempt to resolve an assembly from loaded assemblies
IsSameAs(this AssemblyName, AssemblyName) Compare two assembly names with version-aware logic
ReadResource(this Assembly, string) Read an embedded resource as a string
GetBaubitFormattedAssemblyQualifiedName(this Type) Get simplified assembly-qualified name without version metadata
ReadStringAsync(this Stream) Read a stream's content as a string
CreateInstance<IMyService>(this Type, Type[], object[]) Create instances using specific constructors

TypeResolver

Method Description
TryResolveType(string) Safely resolve a type from its assembly-qualified name

Error Reasons

Reason Description
TypeNotDefined Thrown when a type cannot be resolved from the given assembly-qualified name

Dependencies

  • FluentResults: For functional error handling
  • Baubit.Traceability: For custom error reason types

Development

Building the Project

dotnet build

Running Tests

dotnet test

Creating NuGet Package

dotnet pack -c Release

CI/CD

This project uses CircleCI for continuous integration and deployment:

  • Build: Automated on every commit
  • Test: Unit tests with code coverage reported to Codecov
  • Pack & Publish: NuGet packages published from the master branch
  • Release: Production releases from the release branch

Contributing

Contributions are welcome! Please feel free to submit pull requests or open issues for bugs and feature requests.

License

See the LICENSE file for details.

Author

Prashant Nagoorkar

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Baubit.Reflection:

Package Downloads
Baubit.Configuration

Type-safe configuration builder for .NET with Result pattern error handling and environment variable expansion. Supports JSON files, embedded resources, user secrets, and custom validation with a chainable API.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2025.49.1 1,364 12/1/2025
2025.48.2 895 11/25/2025
2025.47.1 230 11/23/2025
2025.46.1 176 11/15/2025