https://github.com/odonno/converto
A C# library which gives you basic functions for type conversion and object transformation
https://github.com/odonno/converto
convert copy csharp dotnet functional todictionary toobject with
Last synced: 3 months ago
JSON representation
A C# library which gives you basic functions for type conversion and object transformation
- Host: GitHub
- URL: https://github.com/odonno/converto
- Owner: Odonno
- License: mit
- Created: 2018-11-26T13:02:15.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-04T11:49:35.000Z (about 3 years ago)
- Last Synced: 2025-07-20T10:12:34.269Z (3 months ago)
- Topics: convert, copy, csharp, dotnet, functional, todictionary, toobject, with
- Language: C#
- Homepage:
- Size: 41 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Converto
[](https://www.codefactor.io/repository/github/odonno/converto)
| Package | NuGet |
|-------------------|---------------------------------------------------------------------------------------------------------------|
| Converto | [](https://www.nuget.org/packages/Converto/) |
| Converto.SuccincT | [](https://www.nuget.org/packages/Converto.SuccincT/) |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.
```csharp
var newObject = existingObject.Copy();
``````csharp
if (existingObject.TryCopy(out newObject))
{
}
```#### Using SuccincT library
```csharp
var newObjectOption = existingObject.TryCopy();
var newObject = newObjectOption.Value;
```With
The `With` function allows you to create a new object by mutating some properties.
```csharp
var newObject = existingObject.With(new { Name = "Hello" });
``````csharp
if (existingObject.TryWith(new { Name = "Hello" }, out newObject))
{
}
```#### Using SuccincT library
```csharp
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.
```csharp
var newObject = objectOfTypeA.ConvertTo();
``````csharp
if (objectOfTypeA.TryConvertTo(out newObject))
{
}
```#### Using SuccincT library
```csharp
var newObjectOption = objectOfTypeA.TryConvertTo();
var newObject = newObjectOption.Value;
```IsDeepEqual
The `IsDeepEqual` function detects if two objects have strictly the same properties (not necessarily the same object).
```csharp
bool isDeepEqual = object1.IsDeepEqual(object2);
```ToDictionary
The `ToDictionary` function allows you to create a dictionary from an object.
```csharp
var newDictionary = existingObject.ToDictionary();
```ToObject
The `ToObject` function allows you to create an object from a dictionary.
```csharp
var newObjectOfTypeA = existingDictionary.ToObject();
```#### Using SuccincT library
```csharp
var newObjectOption = existingDictionary.TryToObject();
var newObject = newObjectOption.Value;
```