MentalDesk.Fuse 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package MentalDesk.Fuse --version 1.1.0
NuGet\Install-Package MentalDesk.Fuse -Version 1.1.0
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="MentalDesk.Fuse" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MentalDesk.Fuse --version 1.1.0
#r "nuget: MentalDesk.Fuse, 1.1.0"
#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.
// Install MentalDesk.Fuse as a Cake Addin
#addin nuget:?package=MentalDesk.Fuse&version=1.1.0

// Install MentalDesk.Fuse as a Cake Tool
#tool nuget:?package=MentalDesk.Fuse&version=1.1.0

fuse

Fuse is a tiny package that let's you attach properties to .NET types dynamically at runtime.

It provides 3 extension methods that can be used with any object?:

  1. SetFused
  2. GetFused
  3. Fused

SetFused

The SetFused method can be used to associate or attach an arbitrary property to any .net object using a string key.

var myObject = "A simple string";
var myClass = new MyClass { Foo = 42, Bar = "Success!" };
myObject.SetFused("foobar", myClass);

class MyClass 
{
    public int Foo {get; set; }
    public string Bar {get; set; }
}

GetFused

The GetFused method can be used to retrieve properties that have been fused to an object.

var luckyNumber = myObject.GetFused<MyClass>("foobar")!.Foo;
var result = myObject.GetFused<MyClass>("foobar")!.Bar;

Generic overloads

Alternatively you can use the Generic overloads, SetFused<T> and GetFused<T>, which automatically assign a property name based on the type of the value being stored/retrieved.

var myObject = "A simple string";
var myClass = new MyClass { Foo = 42, Bar = "Success!" };
myObject.SetFused<MyClass>(myClass);

var luckyNumber = myObject.GetFused<MyClass>()!.Foo;
var result = myObject.GetFused<MyClass>()!.Bar;

class MyClass 
{
    public int Foo {get; set; }
    public string Bar {get; set; }
}

Fused

Finally, the Fused extension lets you automatically create and bolt an additional property onto any object.

You can see an example of how this is used in the Sample application, but it looks something like this in action:

// We start with a humble string
string brendan = "Brendan Eich (/ˈaɪk/; born July 4, 1961)";
UnpackDetails(brendan);
// And now our string has a aggregate Person property fused to it... no initialisation necessary - Person just
// has to have a parameterless constructor
var firstName = brendan.Fused<Person>().FirstName;

void UnpackDetails(string input)
{
    Regex regex = new Regex(@"(?<first>\w+) (?<last>\w+) \(.*; born (?<dob>.+)\)");
    Match match = regex.Match(input);

    var dob = match.Groups["dob"].Value;
    // Here we fuse some additional properties to the string so that we can use these later on
    input.Fused<Person>().FirstName = match.Groups["first"].Value;
    input.Fused<Person>().LastName = match.Groups["last"].Value;
    input.Fused<Person>().DateOfBirth = DateTime.ParseExact(dob, "MMMM d, yyyy", CultureInfo.InvariantCulture);
}

class Person
{
    public string? FirstName { get; set; }
    public string? LastName { get; set; }
    public DateTime DateOfBirth { get; set; }
}
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 136 8/20/2023
1.1.0 133 8/14/2023
1.0.0 159 8/8/2023
0.9.0 139 8/8/2023