ObjectFlattenerRecomposer 1.1.4

.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 1.1.4
NuGet\Install-Package ObjectFlattenerRecomposer -Version 1.1.4
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="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ObjectFlattenerRecomposer --version 1.1.4
#r "nuget: ObjectFlattenerRecomposer, 1.1.4"
#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=1.1.4

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

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.

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,530 1/16/2021
2.0.0 35,532 10/1/2017
1.1.4 30,044 7/26/2016
1.1.0 1,169 3/1/2016
1.0.0 2,606 1/27/2016

Update to version 1.1.4
- Added Exceptions. Errors will be exposed by SerializationExceptions with useful error information instead of returning false.
- Added EntityPropertyConverterOptions that allows users override the default property name delimiter which is "_".
- Updated object flattening to omit read only properties. Properties need to have at least a private setter to be included as part of object flatenning.