Created
May 23, 2022 12:35
-
-
Save lgolubyev/01931596732bc91d4991aad439434f65 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
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
ExternalEntity entity = new ExternalEntity() | |
{ | |
Id = 1001, | |
FirstName = "Dave", | |
LastName = "Johnson" | |
}; | |
MyEntity convertedEntity = (MyEntity)entity; | |
} | |
} | |
class MyEntity | |
{ | |
public int Id { get; set; } | |
public string FullName { get; set; } | |
public static explicit operator MyEntity(ExternalEntity externalEntity) | |
{ | |
return new MyEntity() | |
{ | |
Id = externalEntity.Id, | |
FullName = externalEntity.FirstName + " " + externalEntity.LastName | |
};} | |
} | |
class ExternalEntity | |
{ | |
public int Id { get; set; } | |
public string FirstName { get; set; } | |
public string LastName { get; set; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment