In one of C# projects I've worked with I've met following piece of code:
var session = new Session
{
Application = /*!!!*/
{
PublicApplicationId = appId
},
LastActivityTime = DateTime.Now - TimeSpan.FromTicks(1)
};
I met it some time ago, but only now I got my hands on it.
I don't have access to the sources anymore, so don't know what Session class was meant.
But I'm wondering how is it possible syntactically?
Why is the Application property initialized by just some JSON-like object in braces?
Any Ideas?
addition: /!!!/ - I put this comment to mark the strange place. there were nothing there, no "new SomeClass"
UPD: thanks for the answer! here is a more human-readable description of this feature: https://fuqua.io/blog/2020/12/a-lesser-known-csharp-feature-nested-object-initializers/