相关疑难解决方法(0)

如何对Object类型的属性使用ShouldSerialize [MemberName]()方法?

我试图使用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)

c# serialization json.net

13
推荐指数
1
解决办法
2万
查看次数

隐藏 web api 响应的属性

我想隐藏Modifiedby,ModifieddateCreateddateweb 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)

c# asp.net-core-webapi

1
推荐指数
1
解决办法
2835
查看次数

标签 统计

c# ×2

asp.net-core-webapi ×1

json.net ×1

serialization ×1