命名参数 有两种写法

1

[JsonProperty(PropertyName = "orderCode")]   // 直接为属性赋值

2

[JsonProperty(propertyName: "orderCode")]     // 为构造方法的参数赋值

 

public sealed class JsonPropertyAttribute : Attribute
{

  // 如果构造方法没有任何参数,则只能用 " = " 号的形式直接为属性赋值

  public JsonPropertyAttribute();


  // 使用" : " 冒号 是调用有参数的构造方法
  public JsonPropertyAttribute(string propertyName);

  

  public string PropertyName { get; set; }

posted @ 2018-03-21 10:02  jamess  阅读(859)  评论(0编辑  收藏  举报