Created
October 23, 2015 14:31
-
-
Save malteb247/23567a0728801c73abdf to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
namespace ExpressionTest | |
{ | |
public class ExternalPerson | |
{ | |
public int Id { get; set; } | |
public string FirstName { | |
get; | |
set; | |
} | |
public string LastName { | |
get; | |
set; | |
} | |
public ExternalPerson () | |
{ | |
} | |
} | |
public class Person | |
{ | |
public long Number { get; set; } | |
public string FullName { | |
get; | |
set; | |
} | |
public static explicit operator Person(ExternalPerson externalEntity) | |
{ | |
return new Person() | |
{ | |
Number = externalEntity.Id, | |
FullName = externalEntity.FirstName + " " + externalEntity.LastName | |
}; | |
} | |
public Person () | |
{ | |
} | |
} | |
public static class Test | |
{ | |
public static void ExplicitOperator() | |
{ | |
ExternalPerson externalPerson = new ExternalPerson () { | |
Id = 1100058, | |
FirstName = "Bob", | |
LastName = "Andrews" | |
}; | |
Console.WriteLine (externalPerson.Id); | |
Console.WriteLine (externalPerson.FirstName); | |
Console.WriteLine (externalPerson.LastName); | |
Person simplePerson = (Person)externalPerson; | |
Console.WriteLine (simplePerson.Number); | |
Console.WriteLine (simplePerson.FullName); | |
Console.WriteLine ("Press enter to exit."); | |
Console.ReadKey (); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment