Open
Description
There are case where you may want to do some additional initialization on a class after the initialization otherwise done in the constructor. It would be helpful to add something like OnInitialized(...)
(probably needs a better name) as a partial method call in the constructor. This would allow situations like the following:
public partial class Contact
{
readonly string name;
readonly string email;
readonly string phoneNumber;
readonly DateTime dateOfBirth;
}
public partial class Rolodex
{
readonly ImmutableList<Contact> contacts;
[UserInitialized(0)]
readonly ImmutableDictionary<string, Contact> _contactsByName;
[UserInitialized(1)]
readonly ImmutableDictionary<DateTime, Contact> _contactsByDob;
partial void InitializeFurther(ref ImmutableDictionary<string, Contact> contactsByName,
ref ImmutableDictionary<DateTime, Contact> contactsByDob)
{
contactsByName = contacts.ToImmutableDictionary(contact=>contact.Name);
contactsByDob = contacts.ToImmutableDictionary(contact=>contact.DateOfBirth);
}
...
public Contact FindByName(string name)
{
return contactsByName[name];
}
}
Here I want to have a Rolodex which adds Contacts using the currently auto-generated AddContacts(...)
method, but I also want to be able to expose methods which work against the user provided field. Right now there is no place for me to hook in and do this sort of thing.
Metadata
Metadata
Assignees
Labels
No labels