Package | NuGet |
---|---|
Converto | |
Converto.SuccincT |
Converto is a C# library which gives you basic functions for type conversion and object transformation.
Copy
The Copy
function allows you to strictly copy an object.
var newObject = existingObject.Copy();
if (existingObject.TryCopy(out newObject))
{
}
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))
{
}
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))
{
}
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();