OneOf.TypeExtensions
0.1.0-beta
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
<PackageReference Include="OneOf.TypeExtensions" Version="0.1.0-beta" />
paket add OneOf.TypeExtensions --version 0.1.0-beta
#r "nuget: OneOf.TypeExtensions, 0.1.0-beta"
// 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
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 | 932 | 12/20/2023 |
1.0.4 | 193 | 12/20/2023 |
1.0.3 | 241 | 12/4/2023 |
1.0.2 | 212 | 11/27/2023 |
0.1.0-beta | 184 | 11/24/2023 |