Table of Contents

Class TypeFns

Namespace
Breeze.Core
Assembly
Breeze.Core.dll

A collection of static methods used to provide additional Type related services.

public static class TypeFns
Inheritance
TypeFns
Inherited Members

Fields

DecimalTypes

Returns an array of decimal types.

public static readonly Type[] DecimalTypes

Field Value

Type[]

IntegerTypes

Returns an array of integer types.

public static readonly Type[] IntegerTypes

Field Value

Type[]

NumericTypes

Returns an array of numeric types.

public static readonly Type[] NumericTypes

Field Value

Type[]

PredefinedTypes

Returns an array of predefined types.

public static readonly Type[] PredefinedTypes

Field Value

Type[]

Methods

ConstructGenericInstance(Type, params Type[])

Constructs a generic instance.

public static object? ConstructGenericInstance(Type genericType, params Type[] argTypes)

Parameters

genericType Type
argTypes Type[]

Returns

object

The new instance; null only when the constructed type is a Nullable<T>.

ConstructGenericInstance(Type, Type[], params object?[])

Constructs a generic instance. Can only access public constructors.

public static object? ConstructGenericInstance(Type genericType, Type[] argTypes, params object?[] constructorParams)

Parameters

genericType Type
argTypes Type[]
constructorParams object[]

Returns

object

The new instance; null only when the constructed type is a Nullable<T>.

FindGenericMethods(Type, string, BindingFlags, Type[]?)

Finds a collection of generic methods.

public static IEnumerable<MethodInfo> FindGenericMethods(Type type, string methodName, BindingFlags flags, Type[]? genericArgTypes)

Parameters

type Type
methodName string

Is case insensitive

flags BindingFlags
genericArgTypes Type[]

Returns

IEnumerable<MethodInfo>

FindIEnumerable(Type?)

public static Type? FindIEnumerable(Type? seqType)

Parameters

seqType Type

Returns

Type

FindMethod(Type, string, bool, Type[])

Finds a specific method.

public static MethodInfo? FindMethod(Type type, string methodName, bool isStatic, Type[] parameterTypes)

Parameters

type Type
methodName string
isStatic bool
parameterTypes Type[]

Returns

MethodInfo

FindMethod(Type, string, BindingFlags, Type[])

Finds a specific method.

public static MethodInfo? FindMethod(Type type, string methodName, BindingFlags flags, Type[] parameterTypes)

Parameters

type Type
methodName string
flags BindingFlags
parameterTypes Type[]

Returns

MethodInfo

FindMethod(Type, string, BindingFlags, Type[]?, Type[])

Finds a specific method.

public static MethodInfo? FindMethod(Type type, string methodName, BindingFlags flags, Type[]? genericArgTypes, Type[] parameterTypes)

Parameters

type Type
methodName string
flags BindingFlags
genericArgTypes Type[]
parameterTypes Type[]

Returns

MethodInfo

FindMethod(Type, string, Type[])

Finds a specific public method.

public static MethodInfo? FindMethod(Type type, string methodName, Type[] parameterTypes)

Parameters

type Type
methodName string
parameterTypes Type[]

Returns

MethodInfo

FindMethods(Type, string, BindingFlags, Type[])

Finds specific methods.

public static IEnumerable<MethodInfo> FindMethods(Type type, string methodName, BindingFlags flags, Type[] parameterTypes)

Parameters

type Type
methodName string
flags BindingFlags
parameterTypes Type[]

Returns

IEnumerable<MethodInfo>

FindMethods(Type, string, BindingFlags, Type[]?, Type[])

Finds all the methods that match specific criteria.

public static IEnumerable<MethodInfo> FindMethods(Type type, string methodName, BindingFlags flags, Type[]? genericArgTypes, Type[] parameterTypes)

Parameters

type Type
methodName string
flags BindingFlags
genericArgTypes Type[]
parameterTypes Type[]

Returns

IEnumerable<MethodInfo>

FindPropertyOrField(Type, string, bool, bool)

Finds a specific public property or field. Will be automatically restricted as well by execution environment restrictions ( e.g. Silverlight).

public static MemberInfo? FindPropertyOrField(Type type, string memberName, bool isPublic, bool isStatic)

Parameters

type Type
memberName string
isPublic bool
isStatic bool

Returns

MemberInfo

FindPropertyOrField(Type, string, BindingFlags)

Finds a specific property or field

public static MemberInfo? FindPropertyOrField(Type type, string memberName, BindingFlags bindingFlags)

Parameters

type Type
memberName string
bindingFlags BindingFlags

Returns

MemberInfo

GetDefaultValue(Type?)

Gets the default value for a specified type.

public static object? GetDefaultValue(Type? type)

Parameters

type Type

Returns

object

GetElementType(Type)

Returns the element type of any enumerable type;

public static Type? GetElementType(Type seqType)

Parameters

seqType Type

Returns

Type

GetGenericArgument(Type)

Gets a single generic argument from a specified type.

public static Type? GetGenericArgument(Type type)

Parameters

type Type

Returns

Type

null if it can't find one or result is ambiguous

GetGroupingInterface(Type)

Returns the IGrouping interface implemented by the type.

public static Type? GetGroupingInterface(Type type)

Parameters

type Type

Returns

Type

May return null if the specified type is not a grouping type

GetMethodByExample<TIn, TOut>(Expression<Func<TIn, TOut>>, params Type[])

For internal use only.

public static MethodInfo GetMethodByExample<TIn, TOut>(Expression<Func<TIn, TOut>> prototypeLambda, params Type[] resolvedTypes)

Parameters

prototypeLambda Expression<Func<TIn, TOut>>
resolvedTypes Type[]

Returns

MethodInfo

Type Parameters

TIn
TOut

GetMethodByExample<TIn1, TIn2, TOut>(Expression<Func<TIn1, TIn2, TOut>>, params Type[])

Find a two-argument method by writing an example call to it, then close it over different types.

public static MethodInfo GetMethodByExample<TIn1, TIn2, TOut>(Expression<Func<TIn1, TIn2, TOut>> prototypeLambda, params Type[] resolvedTypes)

Parameters

prototypeLambda Expression<Func<TIn1, TIn2, TOut>>

A lambda whose body is a call to the wanted method.

resolvedTypes Type[]

The type arguments to close the method over; none leaves it as found.

Returns

MethodInfo

The method, closed over resolvedTypes if it is generic.

Type Parameters

TIn1

First parameter type of the example call.

TIn2

Second parameter type of the example call.

TOut

Return type of the example call.

Remarks

Reflection over overloaded generic methods is awkward and easy to get wrong, so the method is named by a lambda that calls it - the compiler does the overload resolution - and the resulting definition is then re-closed over the types actually wanted.

GetMethodByNameAndType(Type, string, params Type[])

Find a method by name on a type, closing the type over the given type arguments first if it is generic.

public static MethodInfo? GetMethodByNameAndType(Type containingType, string methodName, params Type[] genericTypeArgs)

Parameters

containingType Type

The type declaring the method, open if generic - e.g. typeof(List<>).

methodName string

The method name.

genericTypeArgs Type[]

Type arguments used to close containingType.

Returns

MethodInfo

The method, or null if the type has none by that name.

GetNonNullableType(Type)

Returns either the specified type or its non-nullable counterpart.

public static Type GetNonNullableType(Type type)

Parameters

type Type

Returns

Type

GetNullableType(Type)

Gets the nullable type that corresponds to the given type.

public static Type? GetNullableType(Type type)

Parameters

type Type

Returns

Type

null for a value type that is not one of the predefined numeric, date/time, Boolean, Char or Guid types (e.g. SByte, DateOnly, TimeOnly, enums, custom structs)

GetSelfAndBaseClasses(Type)

Returns a collection of classes (not interfaces) from which the given type directly inherits.

public static IEnumerable<Type> GetSelfAndBaseClasses(Type type)

Parameters

type Type

Returns

IEnumerable<Type>

GetSelfAndBaseTypes(Type)

Returns a collection of types from which the given type directly inherits or implements.

public static IEnumerable<Type> GetSelfAndBaseTypes(Type type)

Parameters

type Type

Returns

IEnumerable<Type>

GetTypeName(Type)

Returns the name of either the specified type or its non-nullable counterpart.

public static string GetTypeName(Type type)

Parameters

type Type

Returns

string

the name of the given type

IsCompatibleWith(Type, Type)

Determines whether the source type is compatible with the given target type.

public static bool IsCompatibleWith(Type source, Type target)

Parameters

source Type
target Type

Returns

bool

Remarks

This is a better implementation than IsAssignableFrom(Type).

IsEnumType(Type)

Returns whether the specified type (or its non-nullable counterpart) represents an enumeration.

public static bool IsEnumType(Type type)

Parameters

type Type

Returns

bool

true if the specified type represents an enumeration; false otherwise

IsGroupingType(Type)

Returns true if the Type is an IGrouping.

public static bool IsGroupingType(Type type)

Parameters

type Type

Returns

bool

IsIntegralType(Type)

Returns whether the specified type (or its non-nullable counterpart) represents an integer type.

public static bool IsIntegralType(Type type)

Parameters

type Type

Returns

bool

IsNullableType(Type)

Returns whether the specified type is a nullable generic type, i.e. Nullable{T}.

public static bool IsNullableType(Type type)

Parameters

type Type

Returns

bool

true if the specified type is a nullable generic type; false otherwise

IsNumericType(Type)

Returns whether the specified type (or its non-nullable counterpart) represents a numeric type.

public static bool IsNumericType(Type type)

Parameters

type Type

Returns

bool

true if the specified type is numeric; false otherwise

IsPredefinedType(Type)

Returns whether the specified type is one of the PredefinedTypes.

public static bool IsPredefinedType(Type type)

Parameters

type Type

Returns

bool

true if the specified type is a predefined type; false otherwise

IsPredefinedType(Type, bool)

Returns whether the specified type is one of the PredefinedTypes and optionally includes nullable versions of the same in the check.

public static bool IsPredefinedType(Type type, bool includeNullable)

Parameters

type Type
includeNullable bool

Returns

bool

IsSignedIntegralType(Type)

Returns whether the specified type (or its non-nullable counterpart) represents a signed integer type.

public static bool IsSignedIntegralType(Type type)

Parameters

type Type

Returns

bool

IsUnsignedIntegralType(Type)

Returns whether the specified type (or its non-nullable counterpart) represents an unsigned integer type.

public static bool IsUnsignedIntegralType(Type type)

Parameters

type Type

Returns

bool

MakeGenericList(Type)

Constructs a generic list.

public static IList MakeGenericList(Type type)

Parameters

type Type

Returns

IList