Skip to content

ReflectionTools Class ​

Definition ​

Class providing numerous methods to facilitate easier use of the System.Reflection namespace

  • Namespace: JASE
  • Assembly: JASE.ReflectionTools.dll

Fields ​

NameDescription
BindingsInstanceStandard bindings for a Class instance
BindingsStaticBindings for static members of a Class

Methods ​

NameDescription
T ConvertValue(object input)Converts the input object to the specified destination type T.
object ConvertValue(object input, Type destinationType)Converts the input object to the specified destination type.
Array CopyArray(Array source)Attempt to perform a deep copy of the provided Array by using CopyObject
IDictionary CopyDictionary(IDictionary dictionary)Performs a 'shallow' copy of the dictionary object passed in
IEnumerable CopyEnumerable(IEnumerable list)Attempt to perform a deep copy of the provided IEnumerable by using CopyObject
IList CopyList(IList list)Attempt to perform a deep copy of the provided list by using CopyObject
T CopyList(IList input)Attempt to perform a deep copy of the provided list by using CopyObject
void CopyMatchingProperties(object from, object to, bool copyNonPublic = null)Copies all properties that match by name from one object to another.
void CopyMatchingProperties(object from, object to, out List<string> changes, bool copyNonPublic = null, string template = null, bool ignoreNullOrEmptyGuid = null, bool useDateTimeStringCompare = null, bool requireExactTypeMatch = null)Copies all properties that match by name from one object to another.
void CopyMatchingProperties(object from, object to, out string changes, bool copyNonPublic = null, string template = null)Copies all properties that match by name from one object to another.
T CopyObject(object input)Attempts to copy the passed object by calling its .Copy() method, if object implements IDictionary it uses reflection to make a shallow copy of the Dictionary contents
object CopyObject(object input)Attempts to copy the passed object by calling its .Copy() method, if object implements IDictionary it uses reflection to make a shallow copy of the Dictionary contents
T CreateObjectFromDictionary(IDictionary<string, object> properties, bool suppressExceptions = null, bool publicOnly = null, bool allowNonPublicConstructor = null, bool jsonPropertyTranslation = null)Creates an instance of the specified type T and populates its properties from a dictionary of values.
T CreateTypeInstance()Activate/Instantiate an instance of a Type
T CreateTypeInstance(object[] args)Activate/Instantiate an instance of a Type
object CreateTypeInstance(Type type)Activate/Instantiate an instance of a Type
object CreateTypeInstance(Type type, object[] args)Activate/Instantiate an instance of a Type and pass args array to the Constructor
Dictionary<string, object> DeepDifferences(object objA, object objB, DeepDiffOptions options = null)Recursively compares two objects and returns a dictionary of differences.
bool DeepEquals(object objA, object objB, DeepEqualOptions options = null)Performs a recursive equality comparison of two objects.
T GetAttribute(Enum enumeration)Returns the attribute decorating a Property
T GetAttribute(MethodInfo method)Returns the attribute decorating a Method
T GetAttribute(PropertyDescriptor descriptor)Returns if property is decorated with the Attribute
T GetAttribute(PropertyInfo property)Returns the attribute decorating a Property
T GetAttribute(Type type)Returns the attribute found
object GetAttribute(PropertyInfo property, string attribute, bool caseInsensitive = null)Returns the attribute decorating a Property
T GetAttributeProperty(PropertyInfo propertyInfo, Type attribute, string property = null)Gets the value of an Attribute Property
T GetAttributeProperty(Type type, Type attribute, string property = null)Identify an Attribute type and return a specific property
object GetDefault(Type type)Gets the default value for a specified type.
void GetDictionaryTypes(IDictionary dict, out Type key, out Type value)Retrieves the key and value type arguments of a generic IDictionary instance, if available.
FieldInfo GetField(Type type, string field, bool caseSensitive = null, BindingFlags flags = null)Returns a FieldInfo from a class
T GetFieldValue(object obj, string field = null, bool caseSensitivePropName = null)Gets the current value on a Field object of a class
object GetFieldValue(object obj, string field = null, bool caseSensitivePropName = null)Gets the current value on a Field object of a class
MethodInfo GetGenericMethod(Type type, string methodName, BindingFlags flags = null, Type[] arguments)Returns the MethodInfo for the requested method name and signature (arguments) If the method is a generic, it converts it before returning
MethodInfo GetGenericMethod(string methodName, BindingFlags flags = null, Type[] arguments)Returns the MethodInfo for the requested method name and signature (arguments) If the method is a generic, it converts it before returning
List<Type> GetImplementingTypes(Type interfaceType, Assembly assembly = null, bool sort = null)Gets the Types within the Assembly that implement the interfaceType
List<FieldInfo> GetListConstants(Type type, BindingFlags flags = null)Return a List of all Constantts defined on a type
List<FieldInfo> GetListFields(Type type, BindingFlags flags = null)Return a List of all FieldInfo's on a type
PropertyInfo[] GetListProperties(Type type, BindingFlags flags = null)Returns an array of PropertyInfo for the type constrained to the BindingFlags specified
MethodInfo GetMethod(Type type, string methodName, BindingFlags flags = null, Type[] arguments)Returns the MethodInfo for the requested method name and signature (arguments)
object[] GetMethodParameterArray(ParameterInfo[] methodParameters, object[] args)Returns an object array based on the expected parameters for a method
Dictionary<string, object> GetObjectPropertyValues(object input)Returns a Dictionary containing the objects property names and values
PropertyInfo GetProperty(Type type, string property, bool caseSensitive = null, BindingFlags bindingFlags = null)Returns the requested PropertyInfo
Type GetPropertyType(Type type, string property, bool caseSensitive = null)Returns the Type (datatype) of the requested peoperty name
Type GetPropertyType(object obj, string property, bool caseSensitive = null)Overload to GetPropertyType allowing the passing of an object rather than a Type. Determines underlying Type of passed object and then processes
List<Type> GetTypes(AppDomain domain, Func<Type, bool> filter)Returns all types in the specified AppDomain that match the given predicate.
List<Type> GetTypes(Assembly assembly, Func<Type, bool> filter)Returns a list of Types filtered by the predicate
List<Type> GetTypesImplementing(AppDomain domain)Returns all concrete types in the specified AppDomain that implement or derive from T.
List<Type> GetTypesImplementing(Assembly assembly)Returns all concrete types in the specified Assembly that implement or derive from T.
object GetValue(object obj, string property = null, bool caseSensitivePropName = null)Gets the value of a specified property from the provided object using reflection.
bool HasAttribute(MethodInfo method, Type attribute)Checks Type to determine if it is decorated with the Attribute
bool HasAttribute(PropertyDescriptor descriptor)Returns TRUE if property is decorated with the Attribute
bool HasAttribute(PropertyInfo property)Returns TRUE if property is decorated with the Attribute
bool HasAttribute(PropertyInfo property, Type attribute)Checks a property to determine if it is decorated with the specified attribute
bool HasAttribute(PropertyInfo property, string attribute, bool caseInsensitive = null)Checks a property to determine if it is decorated with the specified attribute
bool HasAttribute(Type type)Returns TRUE if type is decorated with the Attribute
bool HasAttribute(Type type, Type attribute)Checks Type to determine if it is decorated with the Attribute
bool HasInterface(Type type)Returns true if the given type implements the specified interface.
bool HasInterface(Type type, Type interfaceToCheck)Returns true if the given type implements the specified interface.
bool HasProperty(Type type, string property, bool caseSensitive = null, BindingFlags bindingFlags = null)Checks if provided Type contains the named property
bool HasProperty(object obj, string property, bool caseSensitive = null, BindingFlags bindingFlags = null)Overload to HasProperty allowing passing of an object rather an a Type, gets the underlying Type of the object and then processes. Uses BindingsInstance by default so results align with GetProperty and GetValue.
bool ImplementsInterface(Type type)Checks Type to determine if it implements the interfaceType
bool ImplementsInterface(Type type, Type interfaceType)Checks Type to determine if it implements the interfaceType
bool ImplementsMethod(Type type, string method, BindingFlags flags = null)Checks if the Type implements the requested method
bool InheritsFrom(Type type, Type parent)Returns true if Type inherits from Parent
bool IsEnumerable(Type type)Returns TRUE if type can be enumerated
bool IsEnumerable(Type type)Returns TRUE if type is an enumeration of the generic enumeration type
bool IsEnumerable(Type type, Type enumerationType)Returns TRUE if type is an enumeration of the requested enumeration type
bool IsInteger(object source)Returns if input object can be converted to an int/Int32
bool IsInteger(object source, out int value)Returns if input object can be converted to an int/Int32
bool IsLong(object source)Returns if input object can be converted to a long/Int64
bool IsLong(object source, out long value)Returns if input object can be converted to a long/Int64
bool IsNullable(Type type)Returns true if type is a nullable datatype
bool IsNullable(Type type, out Type underlyingType)Returns true if type is a nullable datatype
bool IsNumeric(object source)Returns if input object can be converted to a Numeric (decimal)
bool IsNumeric(object source, out decimal value)Returns if the input object can be converted to a numeric (Decimal).
bool IsPrimitiveOrValueType(Type type)Determines whether the specified type is a primitive, enum, or common value type such as String, Guid, Decimal, or DateTime.
bool IsUInt(object source, out uint value)Returns if input object can be converted to an int/Int32
void PrintLoadedAssemblies()Prints loaded Assembly list to either the Console or Debug output
Type ResolveType(string assemblyQualifiedName, AppDomain domain)Finds the Type associated with the requested qualified name
Type ResolveType(string assemblyQualifiedName, bool shortName = null, bool prioritizeDynamic = null)Finds the Type associated with the requested qualified name
void SetFieldValue(object obj, string field, object value, bool caseSensitivePropName = null)Sets a value on a Field object of a class
bool SetValue(object obj, string property, object value, bool caseSensitivePropName = null)Sets the value of a specified property on the provided object using reflection. Supports nested property paths (e.g., "User.Address.Street") and automatic instantiation of null objects or arrays.
bool ToBoolean(bool? value)Converts a nullable Boolean to a non-nullable Boolean.
bool ToBoolean(object value)Converts the specified value to a Boolean using internal conversion rules.
bool TryConvert(object input, Type destinationType, out T convertedValue)Attemps to convert the input object to the specified destination type T.
bool TryConvert(object input, Type destinationType, out object convertedValue)Attemps to convert the input object to the specified destination type.
bool TryGetAttribute(PropertyInfo property, out T attribute)Returns TRUE if property is decorated with the Attribute
bool TryGetAttribute(Type type, out T attribute)Returns TRUE if Type is decorated with the Attribute