Show / Hide Table of Contents

# Class FieldAccessor<T, U>

A type containing utilities for accessing non-public fields of objects.

##### Inheritance

Object
FieldAccessor<T, U>

##### Inherited Members

Object.ToString()
Object.Equals(Object)
Object.Equals(Object, Object)
Object.ReferenceEquals(Object, Object)
Object.GetHashCode()
Object.GetType()
Object.MemberwiseClone()

###### Namespace: IPA.Utilities

###### Assembly: IPA.Loader.dll

##### Syntax

    public static class FieldAccessor<T, U>

##### Type Parameters

Name | Description
--- | ---
T | the type that the fields are on
U | the type of the field to access

### Methods

| Improve this Doc View Source

#### Access(ref T, String)

Accesses a field for an object by name.

##### Declaration

    public static U Access(ref T obj, string name)

##### Parameters

Type | Name | Description
--- | --- | ---
T | obj | the object to access the field of
String | name | the name of the field to access

##### Returns

Type | Description
--- | ---
U | a reference to the object at the field

##### Exceptions

Type | Condition
--- | ---
MissingFieldException | if the field does not exist on `T`

##### See Also

GetAccessor(String)
| Improve this Doc View Source

#### Get(T, String)

Gets the value of a field of an object by name.

##### Declaration

    public static U Get(T obj, string name)

##### Parameters

Type | Name | Description
--- | --- | ---
T | obj | the object to access the field of
String | name | the name of the field to access

##### Returns

Type | Description
--- | ---
U | the value of the field

##### Exceptions

Type | Condition
--- | ---
MissingFieldException | if the field does not exist on `T`

##### See Also

Get(ref T, String)
Access(ref T, String)
GetAccessor(String)
| Improve this Doc View Source

#### Get(ref T, String)

Gets the value of a field of an object by name.

##### Declaration

    public static U Get(ref T obj, string name)

##### Parameters

Type | Name | Description
--- | --- | ---
T | obj | the object to access the field of
String | name | the name of the field to access

##### Returns

Type | Description
--- | ---
U | the value of the field

##### Remarks

The only good reason to use this over Get(T, String) is when you are working with a value type, as it prevents a copy.

##### Exceptions

Type | Condition
--- | ---
MissingFieldException | if the field does not exist on `T`

##### See Also

Get(T, String)
Access(ref T, String)
GetAccessor(String)
| Improve this Doc View Source

#### GetAccessor(String)

Gets an FieldAccessor<T, U>.Accessor for the field named `name` on `T`.

##### Declaration

    public static FieldAccessor<T, U>.Accessor GetAccessor(string name)

##### Parameters

Type | Name | Description
--- | --- | ---
String | name | the field name

##### Returns

Type | Description
--- | ---
FieldAccessor.Accessor<> | an accessor for the field

##### Exceptions

Type | Condition
--- | ---
MissingFieldException | if the field does not exist on `T`

| Improve this Doc View Source

#### Set(T, String, U)

Sets the value of a field for an object by name.

##### Declaration

    public static void Set(T obj, string name, U value)

##### Parameters

Type | Name | Description
--- | --- | ---
T | obj | the object to set the field of
String | name | the name of the field
U | value | the value to set it to

##### Remarks

This overload cannot be safely used for value types. Use Set(ref T, String, U) instead.

##### Exceptions

Type | Condition
--- | ---
MissingFieldException | if the field does not exist on `T`

##### See Also

Set(ref T, String, U)
Access(ref T, String)
GetAccessor(String)
| Improve this Doc View Source

#### Set(ref T, String, U)

Sets the value of a field for an object by name.

##### Declaration

    public static void Set(ref T obj, string name, U value)

##### Parameters

Type | Name | Description
--- | --- | ---
T | obj | the object to set the field of
String | name | the name of the field
U | value | the value to set it to

##### Remarks

This overload must be used for value types.

##### Exceptions

Type | Condition
--- | ---
MissingFieldException | if the field does not exist on `T`

##### See Also

Set(T, String, U)
Access(ref T, String)
GetAccessor(String)

### See Also

PropertyAccessor<T, U>