OwnerValueAttribute

Description

sealed class CodeX.OwnerValueAttribute

Derived from

Attribute abstract

The OwnerValue is used on properties to declare ownership of disposable objects.

The following rules depict - based on the ownership status - when a disposable object must be disposed and when disposal must not be performed. Going by these rules will avoid situations where a resource is disposed although it is still being used and situations when a resource is never explicitly disposed, thus wasting system resources.

  • When used on a property:

    ...
    [OwnerValue]
    IDisposable MyObj { set { ... } }
    ...
    [OwnerValue]
    IDisposable MyObj { set { ... }  get { ... } }
    ...

    The property takes ownership on the object that is passed to it as the value, so the storage container from which the value has originated is no longer responsible for disposal.