ObjectFlattenerRecomposer 2.0.0

Object Flattener Recomposer

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, IEnumerable property types to Azure Table Storage.

Added IEnumerable property (List, Array, Dictionary, ...) support to v2.0.0

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);

Install-Package ObjectFlattenerRecomposer -Version 2.0.0
dotnet add package ObjectFlattenerRecomposer --version 2.0.0
<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
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

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);

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);

Release Notes

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.

Version History

Version Downloads Last updated
2.0.0 6,351 10/1/2017
1.1.4 11,014 7/26/2016
1.1.0 341 3/1/2016
1.0.0 939 1/27/2016