Skip to content

Instantly share code, notes, and snippets.

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