Class ReflectionHelper
A set of functions to help with reflection, including referencing custom loaded DLLs by LemonEdge
Inheritance
Inherited Members
Namespace: LemonEdge.Utils
Assembly: Utils.dll
Syntax
public static class ReflectionHelper
Properties
AssembliesLoaded
Indicates if the assemblies have been loaded into the freflection cache
Declaration
public static bool AssembliesLoaded { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
CustomAssemblies
All custom assemblies dynamically loaded by LemonEdge through AddIn Modules
Declaration
public static Assembly[] CustomAssemblies { get; }
Property Value
Type | Description |
---|---|
System.Reflection.Assembly[] |
GetBindingFlagForNonPublicAndPublic
Returns binding flags for finding properties/methodas that are private and public
Declaration
public static BindingFlags GetBindingFlagForNonPublicAndPublic { get; }
Property Value
Type | Description |
---|---|
System.Reflection.BindingFlags |
GetBindingFlagForPublic
Returns binding flags for finding properties/methodas that are public
Declaration
public static BindingFlags GetBindingFlagForPublic { get; }
Property Value
Type | Description |
---|---|
System.Reflection.BindingFlags |
StandardAssemblies
All standard assemblies as part of the LemonEdge application
Declaration
public static Assembly[] StandardAssemblies { get; }
Property Value
Type | Description |
---|---|
System.Reflection.Assembly[] |
Methods
AddAssembly(Assembly, Assembly)
Indicates the system has loaded a specified assembly into the LemonEdge app domain and it should be added to the reflection cache, and can optionally replace
any older version
Declaration
public static void AddAssembly(Assembly assembly, Assembly replace = null)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.Assembly | assembly | Add this assembly to the reflection cache |
System.Reflection.Assembly | replace | Replace this existing assembly in the reflection cache with the specified |
Remarks
This is used by the core LemonEdge system when loading custom addins. As users can change addins this allows the system to replace older versions with newr ones as they are updated.
Deserialize(Type, Byte[], IEnumerable<Type>)
Deserializes from the specified data
into the specified type
Declaration
public static object Deserialize(Type type, byte[] data, IEnumerable<Type> knownTypes)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type the |
System.Byte[] | data | The serialized stream |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Additional known types involved in the original serialization |
Returns
Type | Description |
---|---|
System.Object | A new instance of |
Deserialize(Type, String, IEnumerable<Type>)
Deserializes from the specified stream
into the specified type
Declaration
public static object Deserialize(Type type, string stream, IEnumerable<Type> knownTypes)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type the |
System.String | stream | The serialized stream |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Additional known types involved in the original serialization |
Returns
Type | Description |
---|---|
System.Object | A new instance of |
Deserialize<T>(Byte[], IEnumerable<Type>)
Deserializes from the specified data
into the specified type T
Declaration
public static T Deserialize<T>(byte[] data, IEnumerable<Type> knownTypes)
Parameters
Type | Name | Description |
---|---|---|
System.Byte[] | data | The serialized stream |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Additional known types involved in the original serialization |
Returns
Type | Description |
---|---|
T | A new instance of |
Type Parameters
Name | Description |
---|---|
T | The type the |
Deserialize<T>(String, IEnumerable<Type>)
Deserializes from the specified stream
into the specified type T
Declaration
public static T Deserialize<T>(string stream, IEnumerable<Type> knownTypes)
Parameters
Type | Name | Description |
---|---|---|
System.String | stream | The serialized stream |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Additional known types involved in the original serialization |
Returns
Type | Description |
---|---|
T | A new instance of |
Type Parameters
Name | Description |
---|---|
T | The type the |
GetAllDomainAssemblies()
Return all dlls loaded into the current domain. Excludes any dlls that have subsequently been unloaded.
Declaration
public static IEnumerable<Assembly> GetAllDomainAssemblies()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Reflection.Assembly> | A list of currently loaded assemblies, including custom LemonEdge AddIns that have been loaded |
GetAppInfo()
Returns the location and application name of the currently executing application
Declaration
public static (string Path, string AppName) GetAppInfo()
Returns
Type | Description |
---|---|
System.ValueTuple<System.String, System.String> | The location and application name of the currently executing application |
GetEnumTypes()
Returns a list of all Enum types in the system
Declaration
public static IEnumerable<Type> GetEnumTypes()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | A list of all Enums in the system |
GetEnumValueCustomAttributes<AttrType, EnumType>(EnumType)
Returns the apecified attribute AttrType
against an enum instance of EnumType
Declaration
public static IEnumerable<AttrType> GetEnumValueCustomAttributes<AttrType, EnumType>(this EnumType value)
where AttrType : Attribute where EnumType : Enum
Parameters
Type | Name | Description |
---|---|---|
EnumType | value | The enum value to return the specified attribute |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<AttrType> | An instance of the specified attribute against the specified enum instance |
Type Parameters
Name | Description |
---|---|
AttrType | The type of attribute marked against all enum values |
EnumType | The enum type to retrieve attributes from |
GetNullableType(Type)
Returns the generic type implementation for this type used for System.Nullable<T> implementation
Declaration
public static Type GetNullableType(this Type t)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t | The type that implements System.Nullable<T> |
Returns
Type | Description |
---|---|
System.Type | The generic type implementation of the System.Nullable<T> implementation of this type |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | If this type does not implement System.Nullable<T> then an exception is thrown |
GetPropertyInfo(Type, String, Boolean)
Returns the System.Reflection.PropertyInfo definition for the specifed property against this type
Declaration
public static PropertyInfo GetPropertyInfo(this Type type, string propName, bool throwIfMissing = true)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type that holds the specified property |
System.String | propName | The property to return propertyinfo on |
System.Boolean | throwIfMissing | Indicates if the property isn't found an System.ArgumentOutOfRangeException should be thrown, otherwise null is returned |
Returns
Type | Description |
---|---|
System.Reflection.PropertyInfo | The PropertyInfo for the specified |
Exceptions
Type | Condition |
---|---|
System.ArgumentOutOfRangeException | If |
GetTypeFromFullName(String)
Returns an instance of the type specified from the full name
Declaration
public static Type GetTypeFromFullName(string fullName)
Parameters
Type | Name | Description |
---|---|---|
System.String | fullName | The full name of a given type |
Returns
Type | Description |
---|---|
System.Type | An instance of the type specified by its |
GetTypesInheritingFrom(Assembly, Type, Boolean)
Returns all types from the specified assem
that inherit the specified type
Declaration
public static IEnumerable<Type> GetTypesInheritingFrom(Assembly assem, Type type, bool allowAbstract)
Parameters
Type | Name | Description |
---|---|---|
System.Reflection.Assembly | assem | The assembly to return matching types from |
System.Type | type | The type to retrieve all other types that inherits from it |
System.Boolean | allowAbstract | Indicates if abstract types are to be included in the result set or not |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | A list of all types from the |
GetTypesInheritingFrom(Type, Boolean)
Returns all types that inherit from the specified type
Declaration
public static IEnumerable<Type> GetTypesInheritingFrom(Type type, bool allowAbstract)
Parameters
Type | Name | Description |
---|---|---|
System.Type | type | The type to retrieve all other types that inherits from it |
System.Boolean | allowAbstract | Indicates if abstract types are to be included in the result set or not |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | A list of all types that inherit from |
GetTypesInheritingFrom<T>(Boolean)
Returns all types that inherit from the specified type T
Declaration
public static IEnumerable<Type> GetTypesInheritingFrom<T>(bool allowAbstract)
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | allowAbstract | Indicates if abstract types are to be included in the result set or not |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Type> | A list of all types that inherit from |
Type Parameters
Name | Description |
---|---|
T | The type to retrieve all other types that inherits from it |
GetTypesWithAttribute<T>(Boolean)
Returns a list of all types in the system that are marked with the specified attribute
Declaration
public static IEnumerable<(T AttributeInstance, Type Type)> GetTypesWithAttribute<T>(bool inherit)
where T : Attribute
Parameters
Type | Name | Description |
---|---|---|
System.Boolean | inherit | Indicates that a type should be included if the attribute is marked against its base type and not just itself |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.ValueTuple<T, System.Type>> | A tuple list containing the attribute |
Type Parameters
Name | Description |
---|---|
T | The attribute type to find all types that are marked with it |
Init(IEnumerable<Assembly>)
Can be called to load all the standard lemonedge assemblies into this reflection helper which is also used by the CodeBuilder
This method must be called before using the platform, or load each individual assembly through LoadAssemblies(IEnumerable<Type>)
Requires that all lemonedge assemblies are actuall in the current app domain, so be sure to reference types in utils, api, etc before calling this, or use LoadAssemblies(IEnumerable<Type>) directlyDeclaration
public static void Init(IEnumerable<Assembly> optionalAdditionalAssemblies = null)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Reflection.Assembly> | optionalAdditionalAssemblies | Additional assemblies that should also be included in the loaded assemblies |
IsNullable(Type)
Indicates if this type if nullable, as in is a type of System.Nullable<T>
Declaration
public static bool IsNullable(this Type t)
Parameters
Type | Name | Description |
---|---|---|
System.Type | t | The type to check to see if it is nullable or not |
Returns
Type | Description |
---|---|
System.Boolean | True if this type is of the type System.Nullable<T> |
LoadAssemblies(IEnumerable<Type>)
Forces the system to load assemblies from the specified types into the reflection cache
Declaration
public static IEnumerable<Assembly> LoadAssemblies(IEnumerable<Type> allTypes = null)
Parameters
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<System.Type> | allTypes | List of types in assemblies that you want forced to be loaded in to the reflection cache |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<System.Reflection.Assembly> | A list of all loaded assemblies |
Serialize(Object, IEnumerable<Type>)
Serializes the specified obj
into a string stream
Declaration
public static string Serialize(object obj, IEnumerable<Type> knownTypes)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to be serialized |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Any known types referenced by the |
Returns
Type | Description |
---|---|
System.String | A serialized string of the |
SerializeToBytes(Object, IEnumerable<Type>)
Serializes the specified obj
into a byte array stream
Declaration
public static byte[] SerializeToBytes(object obj, IEnumerable<Type> knownTypes)
Parameters
Type | Name | Description |
---|---|---|
System.Object | obj | The object to be serialized |
System.Collections.Generic.IEnumerable<System.Type> | knownTypes | Any known types referenced by the |
Returns
Type | Description |
---|---|
System.Byte[] | A serialized byte array of the |