ImmutableObjectGraph icon indicating copy to clipboard operation
ImmutableObjectGraph copied to clipboard

Adding deconstruction

Open desarrollo03TR opened this issue 7 years ago • 0 comments

It would be nice if a deconstruct method is auto generated.

Example:

public class Person
{
    public string FirstName { get;  }
    public string LastName { get; }
    public string City { get; }
    public string State { get; }

    public Person(string fname, string lname, string cityName, string stateName)
    {
        FirstName = fname;
        LastName = lname;
        City = cityName;
        State = stateName;
    }     
    public void Deconstruct(out string fname, out string lname, out string city, out string state)
    {
        fname = FirstName;
        lname = LastName;
        city = City;
        state = State;
    }                           
}

With:

var person = new Person("aName", "aLastName", "aCity", "aState");

Deconstruction can be used like:

var (first, last, city, state) = person;

Or:

var (first, last, _, _) = person;

desarrollo03TR avatar Dec 21 '17 04:12 desarrollo03TR