TypeExtensions
Extension methods for System.Type and System.Object that provide enhanced type checking with generic type definition support, and method lookup by name. Used throughout the Paragon framework for reflection-based systems.
Definition
Namespace: Paragon
Assembly: Paragon.dll
public static class TypeExtensionsQuick Lookup
Get type name without generics
type.GetNonGenericName()
Find methods by name
type.GetMethods("MethodName", flags)
Check type assignability (including open generics)
type.IsOfType(targetType)
Check type assignability (generic)
type.IsOfType<IMyInterface>()
Check object's type assignability
obj.IsOfType(targetType)
Check object's type (generic)
obj.IsOfType<IMyInterface>()
Methods
GetNonGenericName
Returns the type name stripped of the generic arity suffix (the backtick and digit, e.g., `2).
public static string GetNonGenericName(this Type type)Returns: The name without the generic parameter count. For example, List1→List, Dictionary2 → Dictionary.
GetMethods (by name)
Returns all methods on a type that match the given name, filtered by binding flags.
type
Type
The type to search
name
string
Method name to filter by
bindingFlags
BindingFlags
Binding flags for the search. Defaults to BindingFlags.Default.
Returns: All MethodInfo objects with the matching name.
This is useful for finding method overloads — GetMethod() throws for ambiguous matches, but GetMethods(name) returns all of them for further filtering.
IsOfType (Type, Type)
Checks whether a type is assignable to a target type, with full support for open generic type definitions. This is the core type-checking method used across the Paragon framework.
type
Type
The type to check
target
Type
The target type to check against
Returns: true if type matches or is assignable to target.
Resolution order:
Exact type equality (
type == target)For non-generic targets:
target.IsAssignableFrom(type)— standard .NET assignabilityFor open generic definitions: checks the type itself, all implemented interfaces, and the entire base type chain for matching generic type definitions
IsOfType<TType> (Type)
Generic convenience overload.
IsOfType (object, Type)
Checks whether an object's runtime type is assignable to the target type. Returns false for null objects.
@object
object
The object to check (null-safe)
target
Type
The target type
Returns: true if the object is non-null and its type matches.
IsOfType<TType> (object)
Generic convenience overload for object type checking.
Open Generic Support
Standard .NET IsAssignableFrom() does not handle open generic type definitions. IsOfType() fills this gap:
The algorithm checks three sources for open generic matches:
The type itself — is
typea closed version of the target's generic definition?All interfaces — does
typeimplement an interface that is a closed version of the target?The base type chain — does any ancestor of
typematch the target's generic definition?
Common Pitfalls
IsOfType on null returns false
The object overloads use ReferenceEquals(@object, null) and return false for null. This differs from is patterns which would also return false but at compile time.
GetNonGenericName on non-generic types
For non-generic types, Split('')` returns the full name unchanged (since there is no backtick). This is safe but the method name may be misleading when applied to non-generic types. {% endhint %}
See Also
MethodInfoExtensions —
HasParameters()usesIsOfType()for parameter matchingInputActionCallback — uses
GetMethods()to find generic wrapper methods
Last updated