Created
October 5, 2011 15:16
-
-
Save Dashue/1264694 to your computer and use it in GitHub Desktop.
Implicit operators
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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