using System.Text.Json.Serialization; class TestClass { [JsonPropertyName("test-id")] public string TestId { get; set; } public static string GetName(string name) => typeof(CompanyInfo).GetProperty(name)?.GetCustomAttribute<JsonPropertyAttribute>()?.Name ?? name; }
using Newtonsoft.Json; class TestClass { [JsonPropertyName("test-id")] public string TestId { get; set; } public static string GetName(string name) => typeof(CompanyInfo).GetProperty(name)?.GetCustomAttribute<JsonPropertyAttribute>()?.PropertyName ?? name; }
Use as:
TestClass.GetName(nameof(TestClass.GetName))
No comments:
Post a Comment