ObjectFlattenerRecomposer 2.0.0

.NET Framework 4.5
There is a newer version of this package available.
See the version list below for details.
dotnet add package ObjectFlattenerRecomposer --version 2.0.0
NuGet\Install-Package ObjectFlattenerRecomposer -Version 2.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ObjectFlattenerRecomposer" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ObjectFlattenerRecomposer --version 2.0.0
#r "nuget: ObjectFlattenerRecomposer, 2.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install ObjectFlattenerRecomposer as a Cake Addin
#addin nuget:?package=ObjectFlattenerRecomposer&version=2.0.0

// Install ObjectFlattenerRecomposer as a Cake Tool
#tool nuget:?package=ObjectFlattenerRecomposer&version=2.0.0

Integrated into Azure Storage SDK v8.0.0.0 https://msdn.microsoft.com/en-us/library/mt775435.aspx https://msdn.microsoft.com/en-us/library/mt775432.aspx

Blog: https://doguarslan.wordpress.com/2016/02/03/writing-complex-objects-to-azure-table-storage/

Provides functionality to flatten complex objects into EntityProperty dictionary and functionality to recompose original complex object from the flattened property dictionary. One usage is that the API allows writing any complex object with nested properties into Azure Table Storage in flattened form wih individual columns. The API also allows you to save Enum, TimeSpan, DateTimeOffset, Nullable property types to Azure Table Storage.

IEnumerable Properties: Lists, Arrays, Dictionaries,...

With V2.0.0 of the api, I have implemented support for any property type that implements IEnumerable interface. That is a big change and it covers as we know most commonly known collection types like List, Array, Dictionary, their generic versions and other interfaces that inherit from IEnumerable like ICollection, IReadOnlyCollection etc. With this change these properties would be automatically converted to json strings when flattened by the api, when reading the entity back from azure, the api will recompose the original property with the correct type and correct values all transparently.

What is the Minimum Requirement to flatten my complex object with ObjectFlattenerRecomposer API?

The minimum requirement is that your properties need to have both Getter and Setter. The Getter and Setter do not need to be public, they can be protected or private. If there is a property that you cannot/do not want to add a Setter even a private one, then you can exclude that property from being flattened by putting the [IgnorePropertyAttribute] to it as explained below. How do I exclude some properties from being flattened? There may be some use cases where you may want to exclude certain properties from being flattened ie. you have some Get only properties and you do not want to add even a private Setter for those or you do not want to write certain properties eventually to table storage in that case all you need to do is to add [IgnorePropertyAttribute] attribute to the top of the properties you want to exclude.

Flattening Composite Objects and Recursive Referenced objects:

A composite object is an object that has a property of its own type. Object Flattener Recomposer API can flatten and recompose composite objects of any depth as long as the properties do not have recursive references ie. referring back to the root or a parent property. In case of recursive referenced objects, v1.1.3 and above versions of the Object Flattener Recomposer API detects the recursive references anywhere along the object graph and exits from flattening operation, returning a null result. This avoids the flattener from going into an infinite loop traversing inside the recursive path in the object graph.

Blog: https://doguarslan.wordpress.com/2016/02/03/writing-complex-objects-to-azure-table-storage/

Usage:

using ObjectFlattenerRecomposer; //Flatten object and convert it to EntityProperty Dictionary Dictionary<string, EntityProperty> flattenedProperties = EntityPropertyConverter.Flatten(complexObject); // Create a DynamicTableEntity and set its PK and RK DynamicTableEntity dynamicTableEntity = new DynamicTableEntity(partitionKey, rowKey); dynamicTableEntity.Properties = flattenedProperties; // Write the DynamicTableEntity to Azure Table Storage using client SDK //Read the entity back from AzureTableStorage as DynamicTableEntity using the same PK and RK DynamicTableEntity entity = [Read from Azure using the PK and RK]; //Convert the DynamicTableEntity back to original complex object. Imagine original complexObject was of type Order. Order order = EntityPropertyConverter.ConvertBack<Order>(entity.Properties);

Product Versions
.NET Framework net45 net451 net452 net46 net461 net462 net463 net47 net471 net472 net48 net481
Compatible target framework(s)
Additional computed target framework(s)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on ObjectFlattenerRecomposer:

Package Downloads
DynamicTableEntityConverter

Converts objects to DynamicTableEntities and DynamicTableEntities back to original objects. Handles conversion of complex objects with complex nested properties. Usage: // Convert Order object to DynamicTableEntity DynamicTableEntity dynamicTableEntity = DynamicTableEntityConverter.ConvertToDynamicTableEntity(order, "pk", "rk"); // Convert DynamicTableEntity back to Order object Order originalOrder = DynamicTableEntityConverter.ConvertToPOCO<Order>(dynamicTableEntity);

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.1 8,518 1/16/2021
2.0.0 35,518 10/1/2017
1.1.4 30,027 7/26/2016
1.1.0 1,169 3/1/2016
1.0.0 2,604 1/27/2016

Update to version 2.0
- Added support for all IEnumerable type properties (List, Array, Dictionary, ICollection, IReadOnlyCollection etc.). Automatically converts these properties to json when writing to table storage. Recreates the original IEnumerable property with correct type when reading from the table.

- Added support for byte type property.