You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
publicpartialclassContact{readonlystringname;readonlystringemail;readonlystringphoneNumber;readonlyDateTimedateOfBirth;}publicpartialclassRolodex{readonlyImmutableList<Contact>contacts;[UserInitialized(0)]readonlyImmutableDictionary<string,Contact>_contactsByName;[UserInitialized(1)]readonlyImmutableDictionary<DateTime,Contact>_contactsByDob;partialvoidInitializeFurther(refImmutableDictionary<string,Contact>contactsByName,refImmutableDictionary<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.
The text was updated successfully, but these errors were encountered:
DamianReeves
changed the title
Add support for "OnInitialized" partial method.
Add support for "InitializeFurther" partial method.
Sep 15, 2016
So to be honest, I started writing this request without remembering that readonly fields need to be initialized only in the constructor so the request ended up being more complex than I initially expected.
An alternative to the above is to allow fine grained control of what get generates per field.
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: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.The text was updated successfully, but these errors were encountered: