Skip to content

Instantly share code, notes, and snippets.

@jakesays-old
Created March 24, 2019 21:26
Show Gist options
  • Save jakesays-old/8f2b0b4f374eee7fc1a677ac5ff470b6 to your computer and use it in GitHub Desktop.
Save jakesays-old/8f2b0b4f374eee7fc1a677ac5ff470b6 to your computer and use it in GitHub Desktop.
//externally exposed data object
public partial class Person
{
public string FirstName { get; private set; }
public string LastName { get; private set; }
}
public partial class Person
{
internal struct Builder
{
private Person _instance;
public Builder(Person instance)
{
_instance = instance;
}
public string FirstName
{
get => _instance.FirstName;
set => _instance.FirstName = value;
}
public string LastName
{
get => _instance.LastName;
set => _instance.LastName = value;
}
}
}
void EditPerson(Person p)
{
//using the builder
Person.Builder builder(p);
builder.FirstName = "foo";
builder.LastName = "bar";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment