KS.Reactor.ksReflectionUtils Class Reference

Reflection utility functions. More...

Static Public Member Functions

static MemberInfo[] GetEditableMembers (Type type, bool includeInherited=true)
 Gets all fields and properties tagged with ksEditable or ksUnityTag on a type. More...
 
static MemberInfo[] GetCloneableMembers (Type type)
 Gets all fields and properties tagged with ksEditable, ksUnityTagAttribute, or ksCloneable on a type. More...
 
static MemberInfo[] GetMembersWithAttribute (Type type, bool includeInherited, params Type[] attributes)
 Gets all fields and properties tagged with any of the given attributes on a type. More...
 
static bool HasAnyAttributes (MemberInfo member, params Type[] attributes)
 Checks if a member has any of the given attributes. More...
 
static Type GetType (MemberInfo memberInfo)
 Gets the type of a field or property. More...
 
static object GetValue (object script, MemberInfo memberInfo)
 Gets the value of a field or property. More...
 
static void SetValue (object script, MemberInfo memberInfo, object value)
 Sets the value of a field or property. More...
 
static T Clone< T > (T script)
 Creates a copy of a script with the value of all members tagged with ksEditable or ksCloneable copied. More...
 

Detailed Description

Reflection utility functions.

Member Function Documentation

◆ Clone< T >()

static T KS.Reactor.ksReflectionUtils.Clone< T > ( script)
static

Creates a copy of a script with the value of all members tagged with ksEditable or ksCloneable copied.

Arrays, lists, and dictionaries are cloned. Other object references will reference the same object.

Template Parameters
TScript to clone.
Parameters
scriptCloned script.
Returns
Type Constraints
T :class 

◆ GetCloneableMembers()

static MemberInfo [] KS.Reactor.ksReflectionUtils.GetCloneableMembers ( Type  type)
static

Gets all fields and properties tagged with ksEditable, ksUnityTagAttribute, or ksCloneable on a type.

Parameters
typeType to get cloneable fields and properties from.
Returns
Cloneable fields and properties from the type.

◆ GetEditableMembers()

static MemberInfo [] KS.Reactor.ksReflectionUtils.GetEditableMembers ( Type  type,
bool  includeInherited = true 
)
static

Gets all fields and properties tagged with ksEditable or ksUnityTag on a type.

Parameters
typeType to get editable fields and properties from.
includeInheritedIf true, will include editable members from base classes.
Returns
Editable fields and properties from the type.

◆ GetMembersWithAttribute()

static MemberInfo [] KS.Reactor.ksReflectionUtils.GetMembersWithAttribute ( Type  type,
bool  includeInherited,
params Type[]  attributes 
)
static

Gets all fields and properties tagged with any of the given attributes on a type.

Parameters
typeType to get tagged fields and properties from.
includeInheritedIf true, will include tagged members from base classes.
attributesAttributes to check for. Members are returned if they have at least one of this attributes.
Returns
Fields and properties that have any of the attributes.

◆ GetType()

static Type KS.Reactor.ksReflectionUtils.GetType ( MemberInfo  memberInfo)
static

Gets the type of a field or property.

Parameters
memberInfoMemberInfo to get type from.
Returns
Type of field or property.

◆ GetValue()

static object KS.Reactor.ksReflectionUtils.GetValue ( object  script,
MemberInfo  memberInfo 
)
static

Gets the value of a field or property.

Parameters
scriptScript containing the field or property.
memberInfoMemberInfo for field or property.
Returns
Value of the field or property.

◆ HasAnyAttributes()

static bool KS.Reactor.ksReflectionUtils.HasAnyAttributes ( MemberInfo  member,
params Type[]  attributes 
)
static

Checks if a member has any of the given attributes.

Parameters
memberMember to check for attributes.
attributesAttributes to check for.
Returns
True if the member has any of the attributes.

◆ SetValue()

static void KS.Reactor.ksReflectionUtils.SetValue ( object  script,
MemberInfo  memberInfo,
object  value 
)
static

Sets the value of a field or property.

Parameters
scriptScript containing the field or property.
memberInfoMemberInfo for the field or property.
valueValue to set.