using Newtonsoft.Json.Serialization;
public static void Main()
string json = SerializeAppliedPropertyAttributes<UiGridColumn>(typeof(PayrollReport));
public static string SerializeAppliedPropertyAttributes<T>(Type targetClass) where T : Attribute
var atts = targetClass.GetProperties().SelectMany(p => p.GetCustomAttributes<T>()).ToList();
JsonSerializerSettings settings = new JsonSerializerSettings
NullValueHandling = NullValueHandling.Ignore,
ContractResolver = new SuppressAttributeTypeIdResolver(),
Formatting = Formatting.Indented
return JsonConvert.SerializeObject(atts, settings);
public class PayrollReport
[UiGridColumn(Name = "fullName", Visible = false, Width = "90")]
public string FullName { get; set; }
[UiGridColumn(Name = "weekStart", CellFilter = "date")]
public DateTime WeekStart { get; set; }
[AttributeUsage(AttributeTargets.All)]
public class UiGridColumn : Attribute
public string CellFilter { get; set; }
public string DisplayName { get; set; }
public string Name { get; set; }
public bool Visible { get; set; }
public string Width { get; set; }
public class SuppressAttributeTypeIdResolver : CamelCasePropertyNamesContractResolver
protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
JsonProperty prop = base.CreateProperty(member, memberSerialization);
if (member.DeclaringType == typeof(Attribute) && member.Name == "TypeId")
prop.ShouldSerialize = obj => false;