laazyj / GeorgeCloney

DeepClone, Serialize, DeSerialize extensions useful for testing
Other
17 stars 3 forks source link

How can I *exclude* one or more properties from being cloned? #3

Closed marcscheuner closed 9 years ago

marcscheuner commented 9 years ago

Assume I have a class like this:

public class Person
{
    public int PersonId { get; set; }

    public string Name { get; set; }
    public string Firstname { get; set; }
}

It is not marked as serializable - just a plain old CLR class.

How can I tell GeorgeCloney not to clone my "primary key" - "PersonId" ? I tried [NonSerialized] but that can only be applied to fields - not properties. Any other way?

laazyj commented 9 years ago

Currently there is no supported way of excluding public properties from being cloned. If you have any suggestions on how to implement this then I'm open to them, but it is a very simple routine that will just clone the entire object.

ghost commented 9 years ago

Then this should be taken as a feature request - this is something I most definitely would need ...

laazyj commented 9 years ago

Sorry but I'm not doing any active development on this project. Please send a pull request if you have a good idea on how to implement