Api Sandbox Internal TypeLibrary
class

TypeLibrary

public class TypeLibrary

Methods

IReadOnlyList<T> GetAttributes()

Get all attributes of this type

ValueTuple<TypeDescription, T>> GetTypesWithAttribute()

Get all attributes of this type. Returns the type description along with the attribute. This will also return types that inherit the attribute from base classes too.

ValueTuple<TypeDescription, T>> GetTypesWithAttribute(Boolean inherited)

Get all attributes of this type. Returns the type description along with the attribute. If inherited is false, we will return only classes that contain this attribute directly.

T GetAttribute(Type t)

Get single attribute of type, from type

IReadOnlyList<T> GetAttributes(Type t)

Get all attribute of type, from all types assignable to type

Object Create(String name, Type targetType, Object[] args = null)

Create a type instance by name and is assignable to given type, with optional arguments for its constructor.

name — Name of the type to create.
targetType — Type "constraint", as in the type instance must be assignable to this given type.
args — Optional arguments for the constructor of the selected type.
T Create(Type type, Object[] args = null)

Create type instance from type.

T Create(String name = null, Boolean complainOnMissing = True)

Create a type instance by name and is assignable to given type.

name — Name of the type to create.
complainOnMissing — Display a warning when requested type name was not found.
T Create(String name, Object[] args, Boolean complainOnMissing = True)

Create a type instance by name and is assignable to given type.

name — Name of the type to create.
args
complainOnMissing — Display a warning when requested type name was not found.
T Create(Int32 ident)

Create a type instance by its identity. See Type).

ValueTuple<MethodDescription, T>> GetMethodsWithAttribute(Boolean onlyStatic = True)

Find all methods with given attribute, optionally non static

IEnumerable<MethodDescription> FindStaticMethods(String methodName)

Find all static methods with given name.

IEnumerable<MethodDescription> FindStaticMethods(String methodName)

Find all static methods with given name and given attribute.

IEnumerable<T> GetMemberAttributes()

Find all member attributes (instances) with given attribute type.

IEnumerable<T> GetMemberAttributes(Boolean staticMembers)

Find all static or non static only member attributes (instances) with given attribute type.

PropertyDescription[] GetPropertyDescriptions(Object obj, Boolean onlyOwn = False)

Get a list of properties on the target object. To do this we'll just call GetDescription( obj.GetType() ) and return .Properties. Will return an empty array if we can't access these properties.

Boolean SetProperty(Object target, String name, Object value)

Set a named property on given object. Will perform extra magic for string inputs and try to convert to target property type.

target — The target object to set a named property on.
name — Name of the property to set.
value — Value for the property.
returns — Whether the property was set or not.
Object GetPropertyValue(Object target, String name)

Try to get a value from a property on an object

Byte[] ToBytes(T value)

Serialize this value to bytes, where possible

Void ToBytes(T value, ByteStream bs)

Serialize this value to bytes, where possible

T FromBytes(Byte[] data)

Deserialize this from bytes. If the type is unknown, T can be an object.

T FromBytes(ReadOnlySpan<Byte> data)
T FromBytes(ByteStream bs)

Deserialize this from bytes. If the type is unknown, T can be an object.

Int32 GetTypeIdent(Type type)

Get hash of a type.

TypeDescription GetType(Type type)

Get the description for a specific type. This will return null if you don't have whitelist access to the type. For constructed generic types, this will give you the description of the generic type definition.

IReadOnlyList<TypeDescription> GetGenericTypes(Type type, Type[] types)

Get a list of types that implement this generic type

IReadOnlyList<TypeDescription> GetTypes(Type type)

Get descriptions for all types that derive from T

TypeDescription GetType(String name)

Find a TypeDescription that derives from , by name

TypeDescription GetType(String name, Boolean preferAddonAssembly)

Find a TypeDescription that derives from T by name, which can be an Alias etc. If preferAddonAssembly is true, then if there are conflicts we'll prefer types that are in addon code.

TypeDescription GetType(String name, Boolean preferAddonAssembly, Boolean exactFullName)

Find a TypeDescription that derives from T by name, which can be an Alias etc. If preferAddonAssembly is true, then if there are conflicts we'll prefer types that are in addon code. If exactFullName is true, the name must match the FullName of the type.

TypeDescription GetType(Type type, String name, Boolean preferAddonAssembly = False, Boolean exactFullName = False)

Find a TypeDescription that derives from T by name, which can be an Alias etc. If preferAddonAssembly is true, then if there are conflicts we'll prefer types that are in addon code.

type — The base type to search for, or null to search all types
name — The name to search for, which can be an alias or the full name depending on the value of
preferAddonAssembly — If true, then if there are conflicts we'll prefer types that are in addon code.
exactFullName — If true, the name must match the FullName (or alias) of the type
IReadOnlyList<TypeDescription> GetTypes()

Get descriptions for all types that derive from T

IEnumerable<TypeDescription> GetTypes()

Get all types

TypeDescription GetType()

Find the description for templated type

Boolean TryGetType(Type t, TypeDescription typeDescription)

Find the description type

Boolean TryGetType(TypeDescription typeDescription)

Find the description type

TypeDescription GetType(String name, Boolean exactFullName = False)

Find a TypeDescription by name

TypeDescription GetTypeByIdent(Int32 ident)

Find a TypeDescription by name

MemberDescription GetMemberByIdent(Int32 ident)

Find a MemberDescription by its Identity

TypeDescription GetType(String name, Type baseType)

Find a TypeDescription that derives from , by name

Type[] GetGenericArguments(Type genericType)

Performs GetGenericArguments with access control checks. Will throw if any arguments aren't in the whitelist.

genericType — Constructed generic type to get the arguments of
Boolean HasAttribute(Type type)

Return true if this type contains this attribute

Boolean CheckValidationAttributes(T obj)

Check if all properties of this class instance pass their ValidationAttribute.

obj — Object to test.
returns — True if all properties pass their validity checks (or if there are no checks), false otherwise.
Boolean CheckValidationAttributes(T obj, String[] errors)

Check if all properties of this class instance pass their ValidationAttribute.

obj — Object to test.
errors — string array of first invalid obj property error
returns — True if all properties pass their validity checks (or if there are no checks), false otherwise.
SerializedObject GetSerializedObject(Object target)

Get a SerializedObject version of this object

SerializedObject GetSerializedObject(Func<Object> fetchTarget, TypeDescription typeDescription, SerializedProperty parent = null)
EnumDescription GetEnumDescription(Type enumType)

Get a class describing the values of an enum

SerializedProperty CreateProperty(String title, Func<T> get, Action<T> set, Attribute[] attributes = null, SerializedObject parent = null)
SerializedProperty CreateProperty(String title, SerializedObject so, Attribute[] attributes = null, SerializedObject parent = null)

Create a serialized property from a SerializedObject

Assembly: Sandbox.Reflection Namespace: Sandbox.Internal Full Name: Sandbox.Internal.TypeLibrary