ObjectWriter NuGet Package

Sets the value to a property of an object by its path from the root.



The object can be a complex object and the property can be multi level deep nested property or it can be a property directly under the root.

ObjectWriter will find the property using the property path parameter and update its value. Property path is the appended names of the properties visited from root to the end node property which we want to set, delimited by the delimiter string parameter.

Usage:

For setting up the properties directly under the object root:
Ie. LineItem class has an int property called ItemId
LineItem lineItem = new LineItem();

ObjectWriter.Set(lineItem, "ItemId", 13, delimiter: null);

For setting up nested property multiple levels below the object root:
Ie.

Invite class has a property called State, which has a property called Recipient, which has a property called Id.
Here is how you can set the Id property (to string value of “outlook”) at the bottom of the object tree in a single line.
Invite invite = new Invite();
ObjectWriter.Set(invite, "State_Recipient_Id", "outlook", delimiter: "_");
This will set invite.State.Recipient.Id to “outlook”
You also do not need to worry about instantiating the properties State or Recipient, ObjectWriter.Set method will instantiate those if they are null along the way.




Got any ObjectWriter Question?





Info

Version: 1.0.0
Author(s): Dogu Arslan
Last Update: Wednesday, September 21, 2016
.NET Fiddle: Create the first Fiddle
NuGet Url: https://www.nuget.org/packages/ObjectWriter


Install
Install-Package ObjectWriter
dotnet add package ObjectWriter
paket add ObjectWriter
ObjectWriter Download (Unzip the "nupkg" after downloading)



Tags



STATS

must-have-score

avg-downloads-per-day

0

days-since-last-release

2767