Created
July 3, 2015 09:09
-
-
Save alber70g/c9bc5cc7854e84407776 to your computer and use it in GitHub Desktop.
Sample c# extension method for Trait in php
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
public class BaseEntity { | |
public Guid Guid { get; set; } | |
public int Id { get; set; } | |
} |
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
public class BaseEntityExtensions { | |
public static string ToJson(this BaseEntity value) { | |
// logic | |
return JsonSerializer.Serialize(value); | |
} | |
} |
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() { | |
var user = new User(); | |
var JsonString = user.ToJson(); | |
// User: { Guid: "lsdfjs09df038...", Id: 2 } | |
} | |
} |
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
public class User : BaseEntity { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment