Skip to content

Instantly share code, notes, and snippets.

@andreea-anastasescu
Created August 16, 2013 08:00
Show Gist options
  • Save andreea-anastasescu/6248117 to your computer and use it in GitHub Desktop.
Save andreea-anastasescu/6248117 to your computer and use it in GitHub Desktop.
Custom attribute for generating root element in json serialization
namespace Me.WebApi.Mobile
{
using System;
/// <summary>
/// Specifies serilaization options for the classes (models) decorated with this attribute.
/// It was introduced to make possible to obtain a 'root' element in the json serilaization of webapi's output used together with <see cref="RootFormatter"/>.
/// </summary>
[System.AttributeUsage(System.AttributeTargets.Class)]
public class JsonCustomRootAttribute:Attribute
{
/// <summary>
/// Specifies the json root title for any class decorated with this attribute.
/// </summary>
public string Title { set; get; }
/// <summary>
/// Specifies the json root title for any generic IEnumerable of the class decorated with this attribute.
/// </summary>
public string CollectionTitle { set; get; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment