Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add collectionSettersMode none #467

Open
kronic opened this issue Dec 22, 2023 · 3 comments
Open

add collectionSettersMode none #467

kronic opened this issue Dec 22, 2023 · 3 comments

Comments

@kronic
Copy link
Contributor

kronic commented Dec 22, 2023

--collectionSettersMode=none

        public Collection<SomeClass> SomeProp
        {
            get
            {
               if(_someProp == null)
               {
                    _someProp = new Collection<SomeClass>();
               }
               return _someProp;
            }
        }
@kronic kronic changed the title collectionSettersMode none add collectionSettersMode none Dec 22, 2023
@mganss
Copy link
Owner

mganss commented Dec 22, 2023

Good suggestion @kronic Would be great if you could tackle this and create a PR 🙏🏻

The implementation in the example above is probably not thread safe. Perhaps we could leverage Lazy<T> here?

private Lazy<Collection<SomeClass>> _someProp = new Lazy<Collection<SomeClass>>();

public Collection<SomeClass> SomeProp
{
    get
    {
       return _someProp.Value;
    }
}

@kronic
Copy link
Contributor Author

kronic commented Dec 25, 2023

@mganss
would two options suit you?
-noneDeferred
-noneLazy

@mganss
Copy link
Owner

mganss commented Dec 31, 2023

@kronic I think the none setter mode is independent of the initialization strategy. Wouldn't it make sense to have just a none mode and an additional command line option that specifies the initialization strategy?

For example --init with values immediate (default, initialization in constructor), none (no initialization, then we can also remove PublicWithoutConstructorInitialization and InitWithoutConstructorInitialization), deferred, and lazy.

We'd need to make sure only sane combinations can be chosen, e.g. a private setter or no setter would require an initialization other than none.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants