我试图使用Newtonsoft.Json中的ShouldSerialize方法阻止类型为object的属性,而没有为其属性分配新值.但我不知道如何实现它,所以请帮我解决这个问题......
这是示例代码
public class Sample1
{
public String name{get;set;}
public int Id{get;set;};
}
Run Code Online (Sandbox Code Playgroud)
这是我的Class,包含上面的类作为其属性之一
public class Container
{
public String Cname{get;set;}
public Sample1 Sample{get;set;};
public bool ShouldSerializeSample()
{
//What should I write here to prevent the Sample property from being serialized when its properties are assigned no new values.
}
}
Run Code Online (Sandbox Code Playgroud) 我想隐藏Modifiedby,Modifieddate和Createddateweb api 响应中的属性。
我尝试使用[JsonOgnore],[IgnoreDataMember]但没有奏效。
[ModelMetadataType(typeof(UserModel))]
partial class TUsers
{
}
public class UserModel
{
public int Userid { get; set; }
[Required]
public string Firstname { get; set; }
public string Middlename { get; set; }
public string Lastname { get; set; }
public int? Modifiedby { get; set; }
public DateTime? Modifieddate { get; set; }
public DateTime? Createddate { get; set; }
}
[HttpGet("{id}")]
public IActionResult Get(int id) …Run Code Online (Sandbox Code Playgroud)