ObjectManipulation adds easy methods to allow you an easier way of manipulating objects throughout your code.
$ dotnet add package DDev.Tooling.ObjectManipulationDDev.Tooling.ObjectManipulation creates easy ways to manipulate objects within C# with ease.
Install the package using Nuget into your project.
Call the various methods depending on your usage as outlined below.
internal class SourceClass
{
public string? Name { get; set; } = "Name";
public string? Nullable { get; set; } = "Nullable";
public string NotNullable { get; set; } = "NotNullable";
public string? Description { get; set; } = "Description";
public int? Number { get; set; } = 5;
}
internal class DestinationClass
{
public string? Name { get; }
public string? Nullable { get; set; }
public string? NotNullable { get; set; }
public string? Description { get; set; }
public int Number { get; set; }
}
var Source = new SourceClass();
Console.Write(JsonSerializer.Serialize(Source, Source.GetType(), new JsonSerializerOptions() { WriteIndented = true }));
var Destination = DDev.Tooling.ObjectManipulation.ConvertObject<DestinationClass>(Source);
Console.Write(JsonSerializer.Serialize(Destination, Destination.GetType(), new JsonSerializerOptions() { WriteIndented = true }));
Source
{
"Name": "Name",
"Nullable": "Nullable",
"NotNullable": "NotNullable",
"Description": "Description",
"Number": 5
}
Destination
{
"Name": null,
"Nullable": "Nullable",
"NotNullable": "NotNullable",
"Description": "Description",
"Number": 5
}
If you find any tools within here helpful, consider buying me a beer - I'd appreciate it.