This is Object Initializers with collection read-only property initialization.
It hurts my head that the left side of the expression is not a setter.
Using a collection initializer you can set the value of a property during the constructor even with no set
defined. Specifically for a collection, the documentation linked above says this:
Collection initializers let you specify one or more element initializers when you initialize a collection type that implements IEnumerable and has Add with the appropriate signature as an instance method or an extension method.
This can be really strange (or cool, depending on how you look at it), because you can build your own Add()
extension method for almost any IEnumerable type and use it to do some really interesting things.
Also remember, when using a property that is also a collection or other property, you do not need a set
to call methods or change property values within this object or collection. Instead, you first get
the reference to the collection, and then use whatever access is provided by that nested property.
For example, let's say you have a variable tokenRequest
that has a property Headers
of type HttpRequestHeaders
. The HttpRequestHeaders
type in turn has an Add()
method. To call that method you first get
the reference to the Headers
property and the call method on that reference. No set
is ever used or needed, and yet you still managed to change a property that only has get
defined.
Collection initializers take advantage of this.