Tixone.Net.Generic.Factory 1.0.0

dotnet add package Tixone.Net.Generic.Factory --version 1.0.0                
NuGet\Install-Package Tixone.Net.Generic.Factory -Version 1.0.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="Tixone.Net.Generic.Factory" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Tixone.Net.Generic.Factory --version 1.0.0                
#r "nuget: Tixone.Net.Generic.Factory, 1.0.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 Tixone.Net.Generic.Factory as a Cake Addin
#addin nuget:?package=Tixone.Net.Generic.Factory&version=1.0.0

// Install Tixone.Net.Generic.Factory as a Cake Tool
#tool nuget:?package=Tixone.Net.Generic.Factory&version=1.0.0                

generic-factory

Generic factory implementation

GenericEnumFactory<T>
Use: public enum VehicleType { Car, Truck, Motorcycle };

public interface IVehicle
{
    void SpeedUp();
}

public class Car: IVehicle
{
    public void SpeedUp()
    {
        Console.WriteLine($"I`m a {this.GetType().Name} at full speed");
    }
}

public class Motorcycle : IVehicle
{
    public void SpeedUp()
    {
        Console.WriteLine($"I`m a {this.GetType().Name} at full speed");
    }
}

public class Truck : IVehicle
{
    public void SpeedUp()
    {
        Console.WriteLine($"I`m a {this.GetType().Name} at full speed");
    }
}

GenericEnumFactory<IVehicle> factory = new GenericEnumFactory<IVehicle>();
factory.Register(VehicleType.Car, () => new Car());
factory.Register(VehicleType.Truck, () => new Truck());
factory.Register(VehicleType.Motorcycle, () => new Motorcycle());

var vehicle = factory.Get(VehicleType.Car);
vehicle.SpeedUp();
Console.ReadLine();

GenericFactory<T, TK> Use:

var Factory = new GenericFactory<int, IVehicle>();
Factory.Register(1, () => new Car());
Factory.Register(2, () => new Truck());
Factory.Register(3, () => new Motorcycle());

var vehicle = gFactory.Get(2);
vehicle.SpeedUp();

var Factory = new GenericFactory<string, IVehicle>();
Factory.Register("car", () => new Car());
Factory.Register("truck", () => new Truck());
Factory.Register("motorcycle", () => new Motorcycle());

var vehicle = Factory.Get("motorcycle");
vehicle.SpeedUp();
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 is compatible.  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. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  net48 is compatible.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • .NETFramework 4.8

    • No dependencies.
  • net5.0

    • No dependencies.
  • net6.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.0.0 2,038 8/11/2021