Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3067

C# Configuration Driven Object to Object Mapping Library

$
0
0

While developing API to API integrations I've been making these as configuration driven as possible to allow reuse while facilitating different customers specific workflows and mappings that they use with their systems. I'm using JSON to configure these object to object mappings with which are then implemented using lots of reflection.

I feel this is a problem that has probably been solved multiple times but I've been unable to find any C# based libraries that provide this functionality. I'd imagine if there's a mature library out there it's probably more flexible and powerful that my current bespoke solution so will meet most or all of my needs, and anything that's missing I could contribute to the library to add the additional functionality needed.

Are there any libraries out there that faciliate driven configuration object to object mapping?

Here's some of the configuration options I currently support which I'd hope to find similiar functionality for:

Simple and hierachical property mapping:

{"DestinationProperty": "Shipment.Order.OrderNumber","ApplySourcePropertyValue": "invoiceNumber"},

Direct value mapping:

{"DestinationProperty": "Creditor.Type","ApplyValue": "Organization"},

Dynamic value mapping:

{"DestinationProperty": "SomeDate","ApplyValue": "/UtcTimeSpan(-0.08:00:00)/"},

/UtcTimeSpan(-0.08:00:00)/ being used to apply a datetime 8 hours before UTC now.

Collection mapping:

{"DestinationProperty": "Shipment.Order.OrderLineCollection[*].Product.Code","ApplySourcePropertyCollectionSize": "OrderLines","ApplyValue": "/Property(OrderLines[*].ProductCode)/-/Property(OrderLines[*].Attribute1)/-/Property(OrderLines[*].Attribute2)/"},

/Property(OrderLines[*].ProductCode)/-/Property(OrderLines[*].Attribute1)/-/Property(OrderLines[*].Attribute2)/ being used here to build a composite value from multiple properties.

Conditional mapping:

[    {"Conditions": [            {"SourceProperty": "Carrier","Operator": "=","Value": "Castle Parcels - NZ - OA/NZC"            },            {"SourceProperty": "OriginZone","Operator": "=","Value": "AKL"            }        ],"DestinationProperty": "Creditor.Key","ApplyValue": "CASPARAKL"      },      {"Conditions": [            {"SourceProperty": "Carrier","Operator": "=","Value": "Castle Parcels - NZ - OA/NZC"            },            {"SourceProperty": "OriginZone","Operator": "=","Value": "CHC"            }        ],"DestinationProperty": "Creditor.Key","ApplyValue": "CASPARCHC"      },]

Single collection item mapping:

{"DestinationProperty": "logisticsCarrier","ApplySourcePropertyValue": "Shipment.OrganizationAddressCollection[].CompanyName","ApplySourcePropertyValueCollections": [        {"CollectionIndex": 0,"SourceProperty": "AddressType","Operator": "=","Value": "TransportCompanyDocumentaryAddress"        }    ]},

My single collection item mapping is not the easiest to understand, probably requiring a bit of refactoring to make it easier to interpret.

Is there anything like this out there? I'd also be interested in learning about non-C# solutions as they may have a better approach to the configuration side of things that I can borrow from.


Viewing all articles
Browse latest Browse all 3067

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>