SkywardApps / popcorn

Popcorn is a .Net Middleware for your RESTful API that allows your consumers to request exactly as much or as little as they need, with no effort from you.
https://skywardapps.github.io/popcorn/
MIT License
59 stars 19 forks source link

Support 'Expanding' into an existing instance #30

Closed undiwahn closed 3 years ago

undiwahn commented 7 years ago

We want to create a variation of the expand method that, instead of trying to instantiate a new object to project into, takes an existing one.

This helps the scenario in which we have an existing item and we want to update it with items from the source object. So perhaps you have a Car and a projection that hides the license plate number:

class Car {
  public string Color {get; set;}
  public string NickName {get; set;}
  public string License {get; set;}
}

class EditableCar {
  public string Color {get; set;}
  public string NickName {get; set;}
}

I may want to get my existing car object, then overlay an EditableCar onto it to overwrite the values as set in EditableCar. So taking:

{
  Color:"black",
  NickName: "nighthawk",
  License: "2AK 8GJ"
}

and expanding the following projection into it

{
  Color:"white",
  NickName":"dayhawk"
}

would result in

{
  Color:"white",
  NickName":"dayhawk",
  License: "2AK 8GJ"   
}
alexbarbato commented 7 years ago

did you want that to function the same as expand with all of the relevant params (source, context, etc.) or simply act as a method on the Expander that allows an object to be projected into another?

undiwahn commented 7 years ago

It should function identically to the existing expand in that respect. It wouldn't need a type hint, somewhat obviously, since the type hint is the type of the object passed in to overlay on to.

On Oct 24, 2017 5:51 PM, "alexbarbato" notifications@github.com wrote:

did you want that to function the same as expand with all of the relevant params (source, context, etc.) or simply act as a method on the Expander that allows an object to be projected into another

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/SkywardApps/popcorn/issues/30#issuecomment-339144285, or mute the thread https://github.com/notifications/unsubscribe-auth/AJNm3qS7iCScPp6h7tby0GudEV8x9qGyks5svlv4gaJpZM4QFH5T .