This library provides a set of extension methods to simplify common tasks related to reflection in C#.
Gets a specified attribute from a member, if present.
public static TAttribute? GetAttribute<TAttribute>(this MemberInfo value)
where TAttribute : AttributeUsage:
MethodInfo methodInfo = // get MethodInfo
MyAttribute? attribute = methodInfo.GetAttribute<MyAttribute>();Gets a list of specified attributes from a member.
public static List<TAttribute> GetAttributes<TAttribute>(this MemberInfo value)
where TAttribute : AttributeUsage:
PropertyInfo propertyInfo = // get PropertyInfo
List<MyAttribute> attributes = propertyInfo.GetAttributes<MyAttribute>();Gets the type of the member.
public static Type GetMemberType(this MemberInfo value)Usage:
FieldInfo fieldInfo = // get FieldInfo
Type fieldType = fieldInfo.GetMemberType();Determines whether the member is a field, property, or method.
public static bool IsField(this MemberInfo value)
public static bool IsProperty(this MemberInfo value)
private static bool IsMethod(this MemberInfo value)Usage:
MethodInfo methodInfo = // get MethodInfo
bool isMethod = methodInfo.IsMethod();Determines whether the specified type is a value type, primitive type, enumeration type, or generic type.
public static bool IsValueType(Type type)
public static bool IsPrimitive(Type type)
public static bool IsEnum(Type type)
public static bool IsGenericType(Type type)Usage:
Type myType = // get Type
bool isEnum = myType.IsEnum();Creates a System.Type object based on the provided TypeBuilder.
public static Type CreateType(TypeBuilder typeBuilder)Usage:
TypeBuilder typeBuilder = // create TypeBuilder
Type createdType = TypeExtensions.CreateType(typeBuilder);Gets the base type of the specified type.
public static Type? BaseType(Type type)Usage:
Type myType = // get Type
Type? baseType = TypeExtensions.BaseType(myType);