Skip to content

A C# library which gives you basic functions for type conversion and object transformation

License

Notifications You must be signed in to change notification settings

Odonno/Converto

Repository files navigation

Converto

CodeFactor

Package NuGet
Converto NuGet
Converto.SuccincT NuGet

Converto is a C# library which gives you basic functions for type conversion and object transformation.

Functions

Copy

The Copy function allows you to strictly copy an object.

var newObject = existingObject.Copy();
if (existingObject.TryCopy(out newObject))
{
}

Using SuccincT library

var newObjectOption = existingObject.TryCopy();
var newObject = newObjectOption.Value;
With

The With function allows you to create a new object by mutating some properties.

var newObject = existingObject.With(new { Name = "Hello" });
if (existingObject.TryWith(new { Name = "Hello" }, out newObject))
{
}

Using SuccincT library

var newObjectOption = existingObject.TryWith(new { Name = "Hello" });
var newObject = newObjectOption.Value;
ConvertTo

The ConvertTo function allows you to create an object of a different type using the matching properties of another object.

var newObject = objectOfTypeA.ConvertTo<TypeB>();
if (objectOfTypeA.TryConvertTo<TypeB>(out newObject))
{
}

Using SuccincT library

var newObjectOption = objectOfTypeA.TryConvertTo<TypeB>();
var newObject = newObjectOption.Value;
IsDeepEqual

The IsDeepEqual function detects if two objects have strictly the same properties (not necessarily the same object).

bool isDeepEqual = object1.IsDeepEqual(object2);
ToDictionary

The ToDictionary function allows you to create a dictionary from an object.

var newDictionary = existingObject.ToDictionary();
ToObject

The ToObject function allows you to create an object from a dictionary.

var newObjectOfTypeA = existingDictionary.ToObject<TypeA>();

Using SuccincT library

var newObjectOption = existingDictionary.TryToObject<TypeA>();
var newObject = newObjectOption.Value;

About

A C# library which gives you basic functions for type conversion and object transformation

Topics

Resources

License

Stars

Watchers

Forks

Languages