VersaTul.Object.Converters
1.0.12
Prefix Reserved
dotnet add package VersaTul.Object.Converters --version 1.0.12
NuGet\Install-Package VersaTul.Object.Converters -Version 1.0.12
<PackageReference Include="VersaTul.Object.Converters" Version="1.0.12" />
paket add VersaTul.Object.Converters --version 1.0.12
#r "nuget: VersaTul.Object.Converters, 1.0.12"
// Install VersaTul.Object.Converters as a Cake Addin #addin nuget:?package=VersaTul.Object.Converters&version=1.0.12 // Install VersaTul.Object.Converters as a Cake Tool #tool nuget:?package=VersaTul.Object.Converters&version=1.0.12
VersaTul Object Converters
VersaTul Object Converters is a project that provides the ability to convert objects into key/value pairs dictionary stores. For example, you can use converters to convert instances of classes into a dictionary representation of the data from the class. This package works with the Collection streamers package.
Features
- IFlattener: An interface that describes the functionality needed to successfully convert from a multi-dimensional object to a one-dimensional key/value pair dictionary with flattened keys.
- IObjectProcessor: An interface that represents functionality that can convert an object into a dictionary of string keys and object values.
- IPropertyProcessor: An interface that describes the functionality needed to successfully process the properties of object instances.
- ObjectProcessor: A concrete implementation of IObjectProcessor.
- PropertyProcessor: A concrete implementation of IPropertyProcessor.
Usage
To use VersaTul Object Converters, you need to install the package and import the relevant classes. Then, you can create instances of ObjectProcessor and PropertyProcessor and use their methods to convert objects into dictionaries. For example:
using VersaTul.ObjectConverters;
// Create an object to convert
var person = new Person
{
Name = "John",
Age = 25,
Address = new Address
{
Street = "123 Main St",
City = "New York",
Zip = "10001"
}
};
// Create an instance of ObjectProcessor
var objectProcessor = new ObjectProcessor();
// Convert the object into a dictionary
var dictionary = objectProcessor.ToDictionary(person);
// Print the dictionary
foreach (var pair in dictionary)
{
Console.WriteLine($"{pair.Key}: {pair.Value}");
}
The output of this code would be:
Name: John
Age: 25
Address.Street: 123 Main St
Address.City: New York
Address.Zip: 10001
You can also use the IFlattener interface to convert a dictionary into a string or another dictionary with flattened keys. For example:
using VersaTul.ObjectConverters;
// Create a dictionary to convert
var dictionary = new Dictionary<string, object>
{
{"Name", "John"},
{"Age", 25},
{"Address", new Dictionary<string, object>
{
{"Street", "123 Main St"},
{"City", "New York"},
{"Zip", "10001"}
}
}
};
// Create an instance of Flattener
var flattener = new Flattener();
// Convert the dictionary into a string
var string = flattener.AsString(dictionary);
// Print the string
Console.WriteLine(string);
The output of this code would be:
Name=John;Age=25;Address.Street=123 Main St;Address.City=New York;Address.Zip=10001
License
This project is licensed under the MIT License - see the LICENSE file for details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Newtonsoft.Json (>= 13.0.3)
- VersaTul.Display.Attributes (>= 1.0.8)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on VersaTul.Object.Converters:
Package | Downloads |
---|---|
VersaTul.Extensions
The VersaTul Extensions project provides a variety of methods for manipulating arrays, performing conversions and other common functionalities. |
|
VersaTul.Collection.Streamers
The VersaTul Collection Streamers provides functionality that enables developers to quickly convert a collection of objects in memory into a data-reader that can be used for Bulk inserting data into a SQL Database, or be used to generate flat files. Developers can use the streamers to: 1. Convert a Collection to a Data-Reader. 2. Convert from a Data-Reader to other file formats such as CSV, TAB or Json. 3. Compress converted data into Zip files. 4. Transport the converted data via e-mail. The Streamers project also works with Display Attributes which is used to manipulate the properties on the objects in the collection such as formatting the data or renaming the property with a desired display name. |
GitHub repositories
This package is not used by any popular GitHub repositories.