> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/api-reference/ks.reactor/ks.reactor.ksreflectionutils.md).

# Class ksReflectionUtils

Namespace: [KS.Reactor](/reactor/api-reference/ks.reactor.md)\
Assembly: KSCommon.dll

Reflection utility functions.

```csharp
public static class ksReflectionUtils
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) ← [ksReflectionUtils](/reactor/api-reference/ks.reactor/ks.reactor.ksreflectionutils.md)

#### Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object\)), [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object-system-object\)), [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype), [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone), [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Methods

### Clone\<T>(T) <a href="#ks_reactor_ksreflectionutils_clone__1___0" id="ks_reactor_ksreflectionutils_clone__1___0"></a>

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.

```csharp
public static T Clone<T>(T script) where T : class
```

#### Parameters

`script` T

Cloned script.

#### Returns

T

#### Type Parameters

`T`

Script to clone.

### GetCloneableMembers(Type) <a href="#ks_reactor_ksreflectionutils_getcloneablemembers_system_type" id="ks_reactor_ksreflectionutils_getcloneablemembers_system_type"></a>

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

```csharp
public static MemberInfo[] GetCloneableMembers(Type type)
```

#### Parameters

`type` [Type](https://learn.microsoft.com/dotnet/api/system.type)

Type to get cloneable fields and properties from.

#### Returns

[MemberInfo](https://learn.microsoft.com/dotnet/api/system.reflection.memberinfo)\[]

Cloneable fields and properties from the type.

### GetEditableMembers(Type, bool) <a href="#ks_reactor_ksreflectionutils_geteditablemembers_system_type_system_boolean" id="ks_reactor_ksreflectionutils_geteditablemembers_system_type_system_boolean"></a>

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

```csharp
public static MemberInfo[] GetEditableMembers(Type type, bool includeInherited = true)
```

#### Parameters

`type` [Type](https://learn.microsoft.com/dotnet/api/system.type)

Type to get editable fields and properties from.

`includeInherited` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

If true, will include editable members from base classes.

#### Returns

[MemberInfo](https://learn.microsoft.com/dotnet/api/system.reflection.memberinfo)\[]

Editable fields and properties from the type.

### GetMembersWithAttribute(Type, bool, params Type\[]) <a href="#ks_reactor_ksreflectionutils_getmemberswithattribute_system_type_system_boolean_system_type" id="ks_reactor_ksreflectionutils_getmemberswithattribute_system_type_system_boolean_system_type"></a>

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

```csharp
public static MemberInfo[] GetMembersWithAttribute(Type type, bool includeInherited, params Type[] attributes)
```

#### Parameters

`type` [Type](https://learn.microsoft.com/dotnet/api/system.type)

Type to get tagged fields and properties from.

`includeInherited` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

If true, will include tagged members from base classes.

`attributes` [Type](https://learn.microsoft.com/dotnet/api/system.type)\[]

Attributes to check for. Members are returned if they have at least one of this attributes.

#### Returns

[MemberInfo](https://learn.microsoft.com/dotnet/api/system.reflection.memberinfo)\[]

Fields and properties that have any of the attributes.

### GetType(MemberInfo) <a href="#ks_reactor_ksreflectionutils_gettype_system_reflection_memberinfo" id="ks_reactor_ksreflectionutils_gettype_system_reflection_memberinfo"></a>

Gets the type of a field or property.

```csharp
public static Type GetType(MemberInfo memberInfo)
```

#### Parameters

`memberInfo` [MemberInfo](https://learn.microsoft.com/dotnet/api/system.reflection.memberinfo)

MemberInfo to get type from.

#### Returns

[Type](https://learn.microsoft.com/dotnet/api/system.type)

Type of field or property.

### GetValue(object, MemberInfo) <a href="#ks_reactor_ksreflectionutils_getvalue_system_object_system_reflection_memberinfo" id="ks_reactor_ksreflectionutils_getvalue_system_object_system_reflection_memberinfo"></a>

Gets the value of a field or property.

```csharp
public static object GetValue(object script, MemberInfo memberInfo)
```

#### Parameters

`script` [object](https://learn.microsoft.com/dotnet/api/system.object)

Script containing the field or property.

`memberInfo` [MemberInfo](https://learn.microsoft.com/dotnet/api/system.reflection.memberinfo)

MemberInfo for field or property.

#### Returns

[object](https://learn.microsoft.com/dotnet/api/system.object)

Value of the field or property.

### HasAnyAttributes(MemberInfo, params Type\[]) <a href="#ks_reactor_ksreflectionutils_hasanyattributes_system_reflection_memberinfo_system_type" id="ks_reactor_ksreflectionutils_hasanyattributes_system_reflection_memberinfo_system_type"></a>

Checks if a member has any of the given attributes.

```csharp
public static bool HasAnyAttributes(MemberInfo member, params Type[] attributes)
```

#### Parameters

`member` [MemberInfo](https://learn.microsoft.com/dotnet/api/system.reflection.memberinfo)

Member to check for attributes.

`attributes` [Type](https://learn.microsoft.com/dotnet/api/system.type)\[]

Attributes to check for.

#### Returns

[bool](https://learn.microsoft.com/dotnet/api/system.boolean)

True if the member has any of the attributes.

### SetValue(object, MemberInfo, object) <a href="#ks_reactor_ksreflectionutils_setvalue_system_object_system_reflection_memberinfo_system_object" id="ks_reactor_ksreflectionutils_setvalue_system_object_system_reflection_memberinfo_system_object"></a>

Sets the value of a field or property.

```csharp
public static void SetValue(object script, MemberInfo memberInfo, object value)
```

#### Parameters

`script` [object](https://learn.microsoft.com/dotnet/api/system.object)

Script containing the field or property.

`memberInfo` [MemberInfo](https://learn.microsoft.com/dotnet/api/system.reflection.memberinfo)

MemberInfo for the field or property.

`value` [object](https://learn.microsoft.com/dotnet/api/system.object)

Value to set.
