constructor/initonly private methods inside of classes #9761
Unanswered
ctigrisht
asked this question in
Language Ideas
Replies: 2 comments 4 replies
-
|
You can already split it out like this: class SuperClass
{
public SuperClass(ConfigStruct someHugeConfig){
_subConfig = PerformInitOnlyConfig(someHugeConfig);
}
private readonly SubConfigStruct _subConfig;
private SubConfigStruct PerformInitOnlyConfig(ConfigStruct config)
{
return config.GetSubConfig();
}
} |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hey!
I consistently come across an issue, that is long constructors for classes that need a lot of config, I end up having to make readonly fields mutable just to split the constructor logic into sane containers.
I'd like to have a new type of method that would allow mutating readonly values, as they could only be called by the constructor.
Here is an example below:
Beta Was this translation helpful? Give feedback.
All reactions