Skip to content

Instantly share code, notes, and snippets.

@Dashue
Created October 5, 2011 15:16
Show Gist options
  • Save Dashue/1264694 to your computer and use it in GitHub Desktop.
Save Dashue/1264694 to your computer and use it in GitHub Desktop.
Implicit operators
static void Main(string[] args)
{
var domainModel = new DomainModel
{
Firstname = "Firstname",
Lastname = "Lastname"
};
ViewModel viewModel = domainModel;
Console.WriteLine(viewModel.Name);
}
private class ViewModel
{
public string Name { get; set; }
}
private class DomainModel
{
public string Firstname { get; set; }
public string Lastname { get; set; }
public static implicit operator ViewModel(DomainModel model)
{
return new ViewModel
{
Name = model.Firstname + " " + model.Lastname
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment