deniszykov.TypeConversion 3.0.1

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

// Install deniszykov.TypeConversion as a Cake Tool
#tool nuget:?package=deniszykov.TypeConversion&version=3.0.1



For historical reasons, .NET has several approaches to value conversion:

  • Explicit/Implicit operators
  • System.Convert class
  • IConvertible interface
  • System.ComponentModel.TypeConverter
  • To, From, Parse, Create methods
  • Constructors (Uri, Guid)
  • Meta types (Enums, Nullable Types).

This package combines all these approaches under one API.


Install-Package deniszykov.TypeConversion 


TypeConversionProvider methods
// generic
ToType Convert<FromType, ToType>(fromValue, [format], [formatProvider]);
bool TryConvert<FromType, ToType>(fromValue, out result, [format], [formatProvider]);
string ConvertToString<FromType>(fromValue, [format], [formatProvider]);

// non-generic
object Convert(fromValue, toType, fromValue, [format], [formatProvider]);
bool TryConvert(fromValue, toType, fromValue, out result, [format], [formatProvider]);


using deniszykov.TypeConversion;

  var conversionProvider = new TypeConversionProvider();
  var timeSpanString = "00:00:01";
  var timeSpan = conversionProvider.Convert<string, TimeSpan>(timeSpanString);
  // with default settings TimeSpan.Parse(value, format, formatProvider) 
  // is used for conversion inside Convert<string, TimeSpan>()


using deniszykov.TypeConversion;

var configuration = new TypeConversionProviderConfiguration
  Options = ConversionOptions.UseDefaultFormatIfNotSpecified

#if NET45
var typeConversionProvider = new TypeConversionProvider(configuration);
var typeConversionProvider = new TypeConversionProvider(Options.Create(configuration));

Or configure via DI

using deniszykov.TypeConversion;
using Microsoft.Extensions.DependencyInjection;

Host.CreateDefaultBuilder().ConfigureServices(IServiceCollection services) => {

  // add configuration
  services.Configure<TypeConversionProviderConfiguration>(options =>
    options.DefaultFormatProvider = CultureInfo.CurrentUICulture;

  // register service
  services.AddSingleton<ITypeConversionProvider, TypeConversionProvider>();

Providing custom conversion between types

using deniszykov.TypeConversion;
using Microsoft.Extensions.DependencyInjection;

Host.CreateDefaultBuilder().ConfigureServices(IServiceCollection services) => {

  services.Configure<TypeConversionProviderConfiguration>(options =>
    // register custom conversion from Uri to string
    options.RegisterConversion<Uri, string>((uri, format, formatProvider) => uri.OriginalString);

Preparing for AOT runtime

using deniszykov.TypeConversion;
using Microsoft.Extensions.DependencyInjection;

Host.CreateDefaultBuilder().ConfigureServices(IServiceCollection services) => {

  services.Configure<TypeConversionProviderConfiguration>(options =>
    // disable optimizations which use dynamic code generation
    options.Options &= ~(ConversionOptions.OptimizeWithExpressions | ConversionOptions.OptimizeWithGenerics);

Key Abstractions

interface ITypeConversionProvider; // provides methods to get IConverter
interface IConverter<FromType, ToType>; // converts values
interface IConversionMetadataProvider; // provides metadata for ITypeConversionProvider
Product Versions
.NET net5.0 net5.0-windows net6.0 net6.0-android net6.0-ios net6.0-maccatalyst net6.0-macos net6.0-tvos net6.0-windows net7.0 net7.0-android net7.0-ios net7.0-maccatalyst net7.0-macos net7.0-tvos net7.0-windows
.NET Core netcoreapp1.0 netcoreapp1.1 netcoreapp2.0 netcoreapp2.1 netcoreapp2.2 netcoreapp3.0 netcoreapp3.1
.NET Standard netstandard1.6 netstandard2.0 netstandard2.1
.NET Framework net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481
MonoAndroid monoandroid
MonoMac monomac
MonoTouch monotouch
Tizen tizen30 tizen40 tizen60
Xamarin.iOS xamarinios
Xamarin.Mac xamarinmac
Xamarin.TVOS xamarintvos
Xamarin.WatchOS xamarinwatchos
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on deniszykov.TypeConversion:

Package Downloads

Pluto is an application server


Package Description


C# DOM bindings to be used with WebView2


Command line parser and binder. Provides API for parsing and binding command line arguments to .NET methods.


A simple, one file graph database!

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.1 698 1/31/2023
3.0.8 2,250 10/7/2022
3.0.6 2,677 4/6/2022
3.0.2 6,558 8/4/2021
3.0.1 1,899 2/26/2021
3.0.0 241 1/29/2021

# 3.0.0
- renamed project to `deniszykov.TypeConversion`
- removed HexConvert, Base64Convert, TypeActivator
- refactored TypeConvert to `ITypeConversionProvider` abstraction and `TypeConversionProvider` implementation
- added configurable behaviour via `TypeConversionProviderConfiguration` and `IConversionMetadataProvider`
- renamed `EnumHelper` to EnumConversionInfo and made it instantiable class instead of static class.