Skip to main content
.NET Framework 4.5.2+

NullValueAttribute Class

Associates a constant with the null value of a property or a field of a simple type.

Namespace: DevExpress.Xpo

Assembly: DevExpress.Xpo.v24.1.dll

NuGet Package: DevExpress.Xpo

Declaration

[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, Inherited = true)]
public sealed class NullValueAttribute :
    Attribute

Remarks

The NullValueAttribute is provided for compatibility with .NET Framework 1.x which doesn’t have support for nullable types. The NullValueAttribute allows null values to be stored in a database and displayed in a UI. Whenever XPO stores a property or a field value to a database or supplies it to a data-bound control, the value is compared with the constant associated with a null value. If they are equal, null (Nothing in VB) is returned for the property or field instead of the associated value. Similarly, when the property’s value is retrieved from the database or the data-bound control, it is compared with a null value. If these values are equal, the NullValueAttribute.Value is returned.

public class Example : XPObject {
    [NullValue(Int32.MinValue)]
    public int NullOnMinValueFieldInt {
     get { return fNullOnMinValueFieldInt; }
     set { SetPropertyValue(nameof(NullOnMinValueFieldInt), ref fNullOnMinValueFieldInt, value); }
 }
 int fNullOnMinValueFieldInt;

    [NullValue(0)]
    public int NullOnZeroFieldInt {
     get { return fNullOnZeroFieldInt; }
     set { SetPropertyValue(nameof(NullOnZeroFieldInt), ref fNullOnZeroFieldInt, value); }
 }
 int fNullOnZeroFieldInt;

    [NullValue("")]
    public string NullOnEmptyStringFieldString {
     get { return fNullOnEmptyStringFieldString; }
     set { SetPropertyValue(nameof(NullOnEmptyStringFieldString), ref fNullOnEmptyStringFieldString, value); }
 }
 string fNullOnEmptyStringFieldString;

    [NullValue("NULL")]
    public string NullOnNULLFieldString {
     get { return fNullOnNULLFieldString; }
     set { SetPropertyValue(nameof(NullOnNULLFieldString), ref fNullOnNULLFieldString, value); }
 }
 string fNullOnNULLFieldString;

}

Note that nullable types are supported by XPO under .NET Framework 2.0 and later.

Inheritance

Object
Attribute
NullValueAttribute
See Also