Wanzyee Studio
VariableInfo

Contain FieldInfo or PropertyInfo and instance to access variable. More...

Public Member Functions

 VariableInfo (string member, Type type, int index=-1)
 Initialize with static field or property found by specified member name. More...
 
 VariableInfo (object instance, string member, int index=-1)
 Initialize with instance field or property found by specified member name. More...
 
 VariableInfo (MemberInfo member, object instance, int index=-1)
 Initialize with specified FieldInfo or PropertyInfo. More...
 
object GetValue ()
 Get the value this reflects to. More...
 
void SetValue (object value)
 Set the value this reflects to. More...
 
override string ToString ()
 Return a string of the variable this points to. More...
 

Public Attributes

bool canRead => null != _valueGetter
 If able to read the reflected value. More...
 
bool canWrite => null != _valueSetter
 If able to write the reflected value. More...
 

Properties

object instance [get]
 The instance owns the MemberInfo to access value. More...
 
MemberInfo member [get]
 The FieldInfo or PropertyInfo to access value. More...
 
int index [get]
 The element index if reflect to an array element, otherwise -1. More...
 
Type valueType [get]
 The type of reflected value, or array item type if reflects to the element. More...
 
bool isStatic [get]
 Determine if this reflects to static member. More...
 
bool isValid [get]
 If this valid currently. More...
 

Detailed Description

Contain FieldInfo or PropertyInfo and instance to access variable.

The main purpose is to access the unknown type value of an UnityEditor.SerializedProperty. Optional to access array element with index in need. Notes, value of an array or array element both belongs to the same member.

Constructor & Destructor Documentation

VariableInfo ( string  member,
Type  type,
int  index = -1 
)

Initialize with static field or property found by specified member name.

Parameters
memberStatic field or property name.
typeType owns the member.
indexIndex to access element, for array only.
Returns
The instance.
VariableInfo ( object  instance,
string  member,
int  index = -1 
)

Initialize with instance field or property found by specified member name.

Mind that it's a copy if the instance is value type.

Parameters
instanceTarget instance.
memberInstance field or property name.
indexIndex to access element, for array only.
Returns
The instance.
VariableInfo ( MemberInfo  member,
object  instance,
int  index = -1 
)

Initialize with specified FieldInfo or PropertyInfo.

Mind that it's a copy if the instance is value type.

Parameters
memberMember info.
instanceTarget instance.
indexIndex to access element, for array only.
Returns
The instance.

Member Function Documentation

object GetValue ( )

Get the value this reflects to.

Returns
The current value.
void SetValue ( object  value)

Set the value this reflects to.

Parameters
valueNew value.
override string ToString ( )

Return a string of the variable this points to.

Returns
A string represents this.

Member Data Documentation

bool canRead => null != _valueGetter

If able to read the reflected value.

Note, this only determines the reflection without checking valid.

bool canWrite => null != _valueSetter

If able to write the reflected value.

Note, this only determines the reflection without checking valid.

Property Documentation

object instance
get

The instance owns the MemberInfo to access value.

MemberInfo member
get

The FieldInfo or PropertyInfo to access value.

int index
get

The element index if reflect to an array element, otherwise -1.

Type valueType
get

The type of reflected value, or array item type if reflects to the element.

bool isStatic
get

Determine if this reflects to static member.

bool isValid
get

If this valid currently.

Return false in situations below:

  1. The instance reflected to is missing.
  2. The array is null or the index is out of range when reflect to an element.