Skip to content

Instantly share code, notes, and snippets.

@malteb247
Created October 23, 2015 14:31
Show Gist options
  • Save malteb247/23567a0728801c73abdf to your computer and use it in GitHub Desktop.
Save malteb247/23567a0728801c73abdf to your computer and use it in GitHub Desktop.
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