未指定默认值时 ConfigurationPropertyAttribute.DefaultValue 的值是多少?

What is the value of ConfigurationPropertyAttribute.DefaultValue when a default value has not been specified?

下面配置的默认值属性显而易见。是 "Arial":

  [ConfigurationProperty("name", DefaultValue = "Arial", IsRequired = true)]
  public string Name
  {
     get { return (string)this["name"]; }
     set { this["name"] = value; }
  }

但是,如果我删除 "DefaultValue" 部分会怎样,如下所示?

  [ConfigurationProperty("name", IsRequired = true)]
  public string Name
  {
     get { return (string)this["name"]; }
     set { this["name"] = value; }
  }

在 Visual Studio 中,属性上 DefaultValue 属性 的值被列为 {object},如果我对其调用 .ToString(),我会得到 "System.Object" .

如何检查属性是否实际指定了默认值?

根据参考来源,看起来对象是私有创建的,这意味着它无法访问:

private object _DefaultValue = ConfigurationElement.s_nullPropertyValue;

(来源:http://referencesource.microsoft.com/#System.Configuration/System/Configuration/ConfigurationPropertyAttribute.cs,31

但是,我能够按如下方式解决问题:

var isDefaultSpecified = propertyAttribute.DefaultValue != null && propertyAttribute.DefaultValue.GetType() != typeof(object);