Another option is to wrap properties inside non-degenerate properties in the same class. Not ideal, because you can have dual properties, but if you can make your generator secure with properties, that would be a pretty good approach.
It was just necessary to solve this problem: Entity Framework generates classes, I want to serialize them in JSON with simpler names.
// GENERATED BY EF public partial class ti_Users { public ti_Users() { this.ti_CardData = new HashSet<ti_CardData>(); this.ti_Orders = new HashSet<ti_Orders>(); } protected int userId { get; set; } protected string userName { get; set; } protected string userEmail { get; set; } protected string userPassHash { get; set; } protected Nullable<System.DateTime> userLastLogin { get; set; } protected string userLastIP { get; set; } public virtual ICollection<ti_CardData> ti_CardData { get; set; } public virtual ICollection<ti_Orders> ti_Orders { get; set; } }
and add-in class:
[JsonObject(memberSerialization: MemberSerialization.OptIn)] public partial class ti_Users { [JsonProperty] public int UserId { get { return this.userId; } set { this.userId = value; } } [JsonProperty] public string Name { get { return this.userName; } set { this.userName = value; } } [JsonProperty] public string Email { get { return this.userEmail; } set { this.userEmail = value; } } [JsonProperty] public string PassHash { get { return this.userPassHash; } set { this.userPassHash = value; } } }
Sten Petrov Nov 15 '12 at 4:14 2012-11-15 04:14
source share