PeanutButter
Loading...
Searching...
No Matches
PeanutButter.Utils.PropertyOrField Class Reference

Provides a single storage / representation for a Property or a Field. More...

Inheritance diagram for PeanutButter.Utils.PropertyOrField:
PeanutButter.Utils.IPropertyOrField

Public Member Functions

 PropertyOrField (PropertyInfo prop)
 Constructs the PropertyOrField around a property.
 
 PropertyOrField (PropertyInfo prop, Type hostingType)
 Constructs the PropertyOrField around a property, relative to an hosting type (ie, without assuming that the DeclaringType is the hosting type for the property)
 
 PropertyOrField (FieldInfo field)
 Constructs the PropertyOrField around a field.
 
 PropertyOrField (FieldInfo field, Type hostingType)
 Constructs the PropertyOrField around a field.
 
object GetValue (object host)
 Gets the value of the property or field for the provided host.
Parameters
host
Returns

 
object GetValueAt (object host, object index)
 Get the value at the provided index into a collection.
Parameters
host
index
Returns

 
bool TryGetValue (object host, out object value, out Exception exception)
 Attempts to get the value of the property.
  • if the getter throws, returns false and the output exception is set
  • if the getter succeeds, returns true and the output value is set
Parameters
host
value
exception
Returns

 
void SetValue (object host, object value)
 Sets the value of the property or field on the provided host.
Parameters
host
value

 
void SetValueAt (object host, object value, object index)
 Sets the value in a collection at that index, if possible.
Parameters
host
value
index

 
void SetValue< T > (ref T host, object value)
 Sets the value for the field or property as found on the provided host.
Parameters
host
value
Template Parameters
T

 

Static Public Member Functions

static PropertyOrField Create (PropertyInfo propertyInfo)
 Creates a PropertyOrField container for a provided PropertyInfo.
 
static PropertyOrField Create (FieldInfo fieldInfo)
 Creates a PropertyOrField container for a provided FieldInfo.
 
static PropertyOrField Find (Type type, string name)
 Attempts to find a property or field with the given name on a type - will scan public, private, static and instance properties and fields. It's up to the caller to know what do to with that (:
 
static PropertyOrField TryFind (Type type, string name)
 Attempts to find a property or field with the given name on a type - will scan public, private, static and instance properties and fields. It's up to the caller to know what do to with that (:
 
static implicit operator PropertyOrField (PropertyInfo prop)
 Implicitly converts a PropertyInfo object to a PropertyOrField.
 
static implicit operator PropertyOrField (FieldInfo field)
 Implicitly converts a FieldInfo object to a FieldOrField.
 

Properties

string Name [get]
 Name of the property or field.
 
Type Type [get]
 Type of the property or field.
 
bool CanWrite [get]
 Write access to property or field.
 
bool CanRead [get]
 Read access to property or field.
 
PropertyOrFieldTypes MemberType [get]
 Is this a Property or a Field?
 
Type DeclaringType [get]
 The type on which this property or field is declared.
 
Type HostingType [get]
 The type from which this property or field is read.
  • this may not be the DeclaringType as the property or field may be inherited
  • this must be explicitly provided by callers

 
int AncestralDistance [get]
 Returns the ancestral distance between the DeclaringType and the HostingType (0 if they are the same type)
 
PropertyInfo PropertyInfo [get]
 the provided prop
 
- Properties inherited from PeanutButter.Utils.IPropertyOrField

Detailed Description

Provides a single storage / representation for a Property or a Field.

Constructor & Destructor Documentation

◆ PropertyOrField() [1/4]

PeanutButter.Utils.PropertyOrField.PropertyOrField ( PropertyInfo  prop)

Constructs the PropertyOrField around a property.

Parameters
prop

◆ PropertyOrField() [2/4]

PeanutButter.Utils.PropertyOrField.PropertyOrField ( PropertyInfo  prop,
Type  hostingType 
)

Constructs the PropertyOrField around a property, relative to an hosting type (ie, without assuming that the DeclaringType is the hosting type for the property)

Parameters
prop
hostingType

◆ PropertyOrField() [3/4]

PeanutButter.Utils.PropertyOrField.PropertyOrField ( FieldInfo  field)

Constructs the PropertyOrField around a field.

Parameters
field

◆ PropertyOrField() [4/4]

PeanutButter.Utils.PropertyOrField.PropertyOrField ( FieldInfo  field,
Type  hostingType 
)

Constructs the PropertyOrField around a field.

Parameters
field
hostingType

Member Function Documentation

◆ Create() [1/2]

static PropertyOrField PeanutButter.Utils.PropertyOrField.Create ( FieldInfo  fieldInfo)
static

Creates a PropertyOrField container for a provided FieldInfo.

Parameters
fieldInfo
Returns

◆ Create() [2/2]

static PropertyOrField PeanutButter.Utils.PropertyOrField.Create ( PropertyInfo  propertyInfo)
static

Creates a PropertyOrField container for a provided PropertyInfo.

Parameters
propertyInfo
Returns

◆ Find()

static PropertyOrField PeanutButter.Utils.PropertyOrField.Find ( Type  type,
string  name 
)
static

Attempts to find a property or field with the given name on a type - will scan public, private, static and instance properties and fields. It's up to the caller to know what do to with that (:

Parameters
type
name
Exceptions
ArgumentExceptionthrown when the property or field is not found
Returns

◆ GetValue()

object PeanutButter.Utils.PropertyOrField.GetValue ( object  host)

Gets the value of the property or field for the provided host.

Parameters
host
Returns

Implements PeanutButter.Utils.IPropertyOrField.

◆ GetValueAt()

object PeanutButter.Utils.PropertyOrField.GetValueAt ( object  host,
object  index 
)

Get the value at the provided index into a collection.

Parameters
host
index
Returns

Implements PeanutButter.Utils.IPropertyOrField.

◆ operator PropertyOrField() [1/2]

static implicit PeanutButter.Utils.PropertyOrField.operator PropertyOrField ( FieldInfo  field)
static

Implicitly converts a FieldInfo object to a FieldOrField.

Parameters
field
Returns

◆ operator PropertyOrField() [2/2]

static implicit PeanutButter.Utils.PropertyOrField.operator PropertyOrField ( PropertyInfo  prop)
static

Implicitly converts a PropertyInfo object to a PropertyOrField.

Parameters
prop
Returns

◆ SetValue()

void PeanutButter.Utils.PropertyOrField.SetValue ( object  host,
object  value 
)

Sets the value of the property or field on the provided host.

Parameters
host
value

Implements PeanutButter.Utils.IPropertyOrField.

◆ SetValue< T >()

void PeanutButter.Utils.PropertyOrField.SetValue< T > ( ref T  host,
object  value 
)

Sets the value for the field or property as found on the provided host.

Parameters
host
value
Template Parameters
T

Implements PeanutButter.Utils.IPropertyOrField.

◆ SetValueAt()

void PeanutButter.Utils.PropertyOrField.SetValueAt ( object  host,
object  value,
object  index 
)

Sets the value in a collection at that index, if possible.

Parameters
host
value
index

Implements PeanutButter.Utils.IPropertyOrField.

◆ TryFind()

static PropertyOrField PeanutButter.Utils.PropertyOrField.TryFind ( Type  type,
string  name 
)
static

Attempts to find a property or field with the given name on a type - will scan public, private, static and instance properties and fields. It's up to the caller to know what do to with that (:

Parameters
type
name
Returns

◆ TryGetValue()

bool PeanutButter.Utils.PropertyOrField.TryGetValue ( object  host,
out object  value,
out Exception  exception 
)

Attempts to get the value of the property.

  • if the getter throws, returns false and the output exception is set
  • if the getter succeeds, returns true and the output value is set
Parameters
host
value
exception
Returns

Implements PeanutButter.Utils.IPropertyOrField.

Property Documentation

◆ AncestralDistance

int PeanutButter.Utils.PropertyOrField.AncestralDistance
get

Returns the ancestral distance between the DeclaringType and the HostingType (0 if they are the same type)

Implements PeanutButter.Utils.IPropertyOrField.

◆ CanRead

bool PeanutButter.Utils.PropertyOrField.CanRead
get

Read access to property or field.

Implements PeanutButter.Utils.IPropertyOrField.

◆ CanWrite

bool PeanutButter.Utils.PropertyOrField.CanWrite
get

Write access to property or field.

Implements PeanutButter.Utils.IPropertyOrField.

◆ DeclaringType

Type PeanutButter.Utils.PropertyOrField.DeclaringType
get

The type on which this property or field is declared.

Implements PeanutButter.Utils.IPropertyOrField.

◆ HostingType

Type PeanutButter.Utils.PropertyOrField.HostingType
get

The type from which this property or field is read.

  • this may not be the DeclaringType as the property or field may be inherited
  • this must be explicitly provided by callers

Implements PeanutButter.Utils.IPropertyOrField.

◆ Name

string PeanutButter.Utils.PropertyOrField.Name
get

Name of the property or field.

Implements PeanutButter.Utils.IPropertyOrField.

◆ Type

Type PeanutButter.Utils.PropertyOrField.Type
get

Type of the property or field.

Implements PeanutButter.Utils.IPropertyOrField.


The documentation for this class was generated from the following file: