OneOf.TypeExtensions 0.1.0-beta

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

// Install OneOf.TypeExtensions as a Cake Tool
#tool nuget:?package=OneOf.TypeExtensions&version=0.1.0-beta&prerelease

OneOf.TypeExtensions

An incremental source generator that creates extension methods for OneOf<> types for more readable code.

Installation

Via nuget NuGet\Install-Package OneOf.TypeExtensions

Example Generated Code

For the type OneOf<int, string>, these extension methods will be generated.

// <auto-generated>

using OneOf;

public static partial class OneOfTypeExtensions
{
    public static bool IsString(this OneOf<string, int> oneOf)
    {
        return oneOf.IsT0;
    }
    public static string AsString(this OneOf<string, int> oneOf)
    {
        return oneOf.AsT0;
    }
    public static OneOf<TResult, int> MapString<TResult>(this OneOf<string, int> oneOf, Func<string, TResult> mapFunc)
    {
        return oneOf.MapT0(mapFunc);
    }
    public static bool TryPickString(this OneOf<string, int> oneOf, out string value, out int remainder)
    {
        return oneOf.TryPickT0(out value, out remainder);
    }
    public static bool IsInt(this OneOf<string, int> oneOf)
    {
        return oneOf.IsT1;
    }
    public static int AsInt(this OneOf<string, int> oneOf)
    {
        return oneOf.AsT1;
    }
    public static OneOf<string, TResult> MapInt<TResult>(this OneOf<string, int> oneOf, Func<int, TResult> mapFunc)
    {
        return oneOf.MapT1(mapFunc);
    }
    public static bool TryPickInt(this OneOf<string, int> oneOf, out int value, out string remainder)
    {
        return oneOf.TryPickT1(out value, out remainder);
    }
}

Supported Types

I believe the generator should support practically any type, if you find a type or combination of types that causes an error, feel free to create an issue or submit a PR.

Special consideration was given to support these types

  • Nullable value types int?
  • Nullable annotated reference types string?
  • Value Tuples (int?, string?)
  • Generics List<int?>
  • Multiple Generics Dictionary<string?, int?>
  • Nested generics List<List<int?>>
  • Nested types Class1.Class2
  • Any combination of the above
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.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.5 259 12/20/2023
1.0.4 154 12/20/2023
1.0.3 206 12/4/2023
1.0.2 167 11/27/2023
0.1.0-beta 146 11/24/2023