using System.ComponentModel.DataAnnotations;
using System.ComponentModel;
public static void Main()
var stud = new Student("this is secret")
Console.WriteLine(TypeDescriptor.GetAttributes(typeof(Student))[0]);
foreach (PropertyDescriptor descriptor in
TypeDescriptor.GetProperties(typeof(Student)))
Console.WriteLine("*******************************");
Console.WriteLine($"Property Name: {descriptor.Name}");
foreach (Attribute attribute in descriptor.Attributes)
Console.WriteLine($"Attribute Name: {attribute}");
var result = JsonConvert.SerializeObject(stud);
var restoredStudent = JsonConvert.DeserializeObject(result, typeof(Student)) as Student;
Console.WriteLine(restoredStudent.WhatIsTheSecret());
[MetadataType(typeof(StudentSerializationConfig))]
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
private readonly string _secret;
public Student(string secret)
public string WhatIsTheSecret()
public class StudentSerializationConfig
[JsonProperty(PropertyName = "Secret")]
private readonly string _secret;
[JsonProperty(PropertyName = "StudentFirstName")]
public string FirstName { get; set; }
[JsonProperty(PropertyName = "StudentLastName")]
public string LastName { get; set; }
[System.Text.Json.Serialization.JsonIgnore]
public int Age { get; set; }