Provides extension methods to set and retrieve metadata on any object. Under the hood, these methods use a ConditionalWeakTable to store your metadata, so the metadata is garbage-collected when your managed objects are garbage-collected.
More...
|
static void | SetMetadata (this object parent, string key, object value) |
| Sets an arbitrary piece of metadata on a managed object. This metadata has the same lifetime as your object, meaning it will be garbage-collected when your object is garbage-collected, assuming nothing else is referencing it.
|
static T | GetMetadata< T > (this object parent, string key) |
| Attempts to retrieve a piece of metadata for an object. When the metadata key for the object is unknown, returns the default value for the type requested, eg 0 for ints, null for strings and objects. Note that if metadata exists for the requested key but not for the type requested, a type-casting exception will be thrown.
|
static T | GetMetadata< T > (this object parent, string key, T defaultValue) |
| Attempts to retrieve a piece of metadata for an object. When the metadata key for the object is unknown, returns the default value for the type requested, eg 0 for ints, null for strings and objects. Note that if metadata exists for the requested key but not for the type requested, a type-casting exception will be thrown. This overload allows specifying a default value.
|
static bool | HasMetadata< T > (this object parent, string key) |
| Tests if a parent object has a piece of metadata with the provided type.
|
static bool | HasMetadata (this object parent) |
| Tests if an object has any metadata stored against it at all.
|
static bool | HasMetadata (this object parent, string key) |
| Tests if an object has metadata with the provided key.
|
static void | DeleteMetadata (this object parent) |
| Deletes all metadata associated with the object, if any.
|
static void | DeleteMetadata (this object parent, string key) |
| Deletes the metadata identified by the key for this object, if found.
|
static bool | TryGetMetadata< T > (this object parent, string key, out T result) |
| Try get the named metadata for the provided type.
|
static void | CopyAllMetadataTo (this object parent, object target) |
| Clones all the metadata from parent to target.
|
Provides extension methods to set and retrieve metadata on any object. Under the hood, these methods use a ConditionalWeakTable to store your metadata, so the metadata is garbage-collected when your managed objects are garbage-collected.
◆ CopyAllMetadataTo()
void PeanutButter.Utils.MetadataExtensions.CopyAllMetadataTo |
( |
this object | parent, |
|
|
object | target ) |
|
static |
Clones all the metadata from parent to target.
- will overwrite target data with the same key!
- Parameters
-
◆ DeleteMetadata() [1/2]
void PeanutButter.Utils.MetadataExtensions.DeleteMetadata |
( |
this object | parent | ) |
|
|
static |
Deletes all metadata associated with the object, if any.
- Parameters
-
◆ DeleteMetadata() [2/2]
void PeanutButter.Utils.MetadataExtensions.DeleteMetadata |
( |
this object | parent, |
|
|
string | key ) |
|
static |
Deletes the metadata identified by the key for this object, if found.
- Parameters
-
◆ GetMetadata< T >() [1/2]
T PeanutButter.Utils.MetadataExtensions.GetMetadata< T > |
( |
this object | parent, |
|
|
string | key ) |
|
static |
Attempts to retrieve a piece of metadata for an object. When the metadata key for the object is unknown, returns the default value for the type requested, eg 0 for ints, null for strings and objects. Note that if metadata exists for the requested key but not for the type requested, a type-casting exception will be thrown.
- Parameters
-
parent | Parent object to query against |
key | Key to query for |
- Template Parameters
-
- Returns
◆ GetMetadata< T >() [2/2]
T PeanutButter.Utils.MetadataExtensions.GetMetadata< T > |
( |
this object | parent, |
|
|
string | key, |
|
|
T | defaultValue ) |
|
static |
Attempts to retrieve a piece of metadata for an object. When the metadata key for the object is unknown, returns the default value for the type requested, eg 0 for ints, null for strings and objects. Note that if metadata exists for the requested key but not for the type requested, a type-casting exception will be thrown. This overload allows specifying a default value.
- Parameters
-
parent | Parent object to query against |
key | Key to query for |
defaultValue | |
- Template Parameters
-
- Returns
◆ HasMetadata() [1/2]
bool PeanutButter.Utils.MetadataExtensions.HasMetadata |
( |
this object | parent | ) |
|
|
static |
Tests if an object has any metadata stored against it at all.
- will always return false for a null object
- Parameters
-
- Returns
◆ HasMetadata() [2/2]
bool PeanutButter.Utils.MetadataExtensions.HasMetadata |
( |
this object | parent, |
|
|
string | key ) |
|
static |
Tests if an object has metadata with the provided key.
- will always return false for a null object
- Parameters
-
- Returns
◆ HasMetadata< T >()
Tests if a parent object has a piece of metadata with the provided type.
- Parameters
-
parent | Parent object to search against |
key | Key to search for |
- Template Parameters
-
T | Expected type of metadata |
- Returns
◆ SetMetadata()
void PeanutButter.Utils.MetadataExtensions.SetMetadata |
( |
this object | parent, |
|
|
string | key, |
|
|
object | value ) |
|
static |
Sets an arbitrary piece of metadata on a managed object. This metadata has the same lifetime as your object, meaning it will be garbage-collected when your object is garbage-collected, assuming nothing else is referencing it.
- Parameters
-
parent | Object to store metadata against |
key | Name of the metadata item to set |
value | Value to store |
◆ TryGetMetadata< T >()
bool PeanutButter.Utils.MetadataExtensions.TryGetMetadata< T > |
( |
this object | parent, |
|
|
string | key, |
|
|
out T | result ) |
|
static |
Try get the named metadata for the provided type.
- Parameters
-
- Template Parameters
-
- Returns
The documentation for this class was generated from the following file:
- source/Utils/PeanutButter.Utils/MetadataExtensions.cs