PropertyDescriptor.ShouldSerializeValue 方法

当在派生类中被重写时,确定一个值,该值指示是否需要永久保存此属性的值。

**命名空间:**System.ComponentModel
**程序集:**System(在 system.dll 中)

语法

声明
Public MustOverride Function ShouldSerializeValue ( _
    component As Object _
) As Boolean
用法
Dim instance As PropertyDescriptor
Dim component As Object
Dim returnValue As Boolean

returnValue = instance.ShouldSerializeValue(component)
public abstract bool ShouldSerializeValue (
    Object component
)
public:
virtual bool ShouldSerializeValue (
    Object^ component
) abstract
public abstract boolean ShouldSerializeValue (
    Object component
)
public abstract function ShouldSerializeValue (
    component : Object
) : boolean

参数

  • component
    具有要检查其持久性的属性的组件。

返回值

如果属性应该被永久保存,则为 true;否则为 false

备注

通常,通过反射实现此方法。

给继承者的说明 当在派生类中被重写时,如果属性的当前值与其默认值不同,则此方法返回 true。它通过先查找 DefaultValueAttribute 来查找默认值。如果此方法找到该属性 (Attribute),它将该属性 (Attribute) 的值与属性 (Property) 的当前值进行比较。如果此方法找不到 DefaultValueAttribute,它将查找您需要实现的“ShouldSerializeMyProperty”方法。如果找到此方法,则 ShouldSerializeValue 将调用它。如果此方法找不到 DefaultValueAttribute 或“ShouldSerializeMyProperty”方法,则它将无法创建优化,并且返回 true

平台

Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0、1.0

请参见

参考

PropertyDescriptor 类
PropertyDescriptor 成员
System.ComponentModel 命名空间