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

Option: Don't clone private fields and properties #4

Open
marcelltoth opened this issue Dec 8, 2019 · 3 comments
Open

Option: Don't clone private fields and properties #4

marcelltoth opened this issue Dec 8, 2019 · 3 comments
Labels
enhancement New feature or request

Comments

@marcelltoth
Copy link
Owner

This issue is a followup on @IgorMamushin's feature request in #3.

As far as I understand the request is about adding an option for not cloning private fields.

@marcelltoth marcelltoth added the enhancement New feature or request label Dec 8, 2019
@IgorMamushin
Copy link

Sometimes i want get object with clone only public property and field. But some property can be set in constructor, like this:

class MyClass
{
    private Dictionary<int, string> _myPrivate

    public MyClass()
    {
        _myPrivate = new Dictionary<int, string>();
    }
}

I think you can use new clone strategy with Expression.New() and foreach on public property/field, for generate clone func.
If class have no empty ctor, cloner can return Exception.

@marcelltoth
Copy link
Owner Author

The problem with this solution is that it creates a very strict requirement of having a parameterless constructor. That's certainly not worth it.

Cloud you not use the ignore attribute you proposed in #5?

@IgorMamushin
Copy link

Yep. I think if you want clone only public properties/fields you need create object with constructor. It can be contract for this mode. Or do something with initialize private field from constructor.

It's not that simple. :)

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

No branches or pull requests

2 participants