Skip to content

Instantly share code, notes, and snippets.

@sdether
Created March 13, 2014 17:01
Show Gist options
  • Save sdether/9532422 to your computer and use it in GitHub Desktop.
Save sdether/9532422 to your computer and use it in GitHub Desktop.
Easy immutable object derivation
public class Immutable {
public class Person {
public readonly string Firstname;
public readonly string Lastname;
public Person(string firstname, string lastname) {
Firstname = firstname;
Lastname = lastname;
}
public Person With(string firstname = null, string lastname = null) {
return new Person(firstname ?? this.Firstname, lastname ?? this.Lastname);
}
}
public void Example() {
var dad = new Person(
firstname: "Joe",
lastname: "Smith"
);
var son = dad.With(firstname: "Joe Jr.");
}
}
@klumsy
Copy link

klumsy commented Nov 6, 2014

Interesting, but sad you have to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment