Skip to main content

ReflectionExtensions

Assembly: ServiceStack.Text.dll​
View Source​
Declaration
public static class ReflectionExtensions

Fields​

DataMember​

View Source​
Declaration
public const string DataMember = "DataMemberAttribute"

Methods​

GetTypeCode(Type)​

View Source​
Declaration
public static TypeCode GetTypeCode(this Type type)
Returns​

System.TypeCode

Parameters​
TypeName
System.Typetype

IsInstanceOf(Type, Type)​

View Source​
Declaration
public static bool IsInstanceOf(this Type type, Type thisOrBaseType)
Returns​

System.Boolean

Parameters​
TypeName
System.Typetype
System.TypethisOrBaseType

HasGenericType(Type)​

View Source​
Declaration
public static bool HasGenericType(this Type type)
Returns​

System.Boolean

Parameters​
TypeName
System.Typetype

FirstGenericType(Type)​

View Source​
Declaration
public static Type FirstGenericType(this Type type)
Returns​

System.Type

Parameters​
TypeName
System.Typetype

GetTypeWithGenericTypeDefinitionOfAny(Type, Type[])​

View Source​
Declaration
public static Type GetTypeWithGenericTypeDefinitionOfAny(this Type type, params Type[] genericTypeDefinitions)
Returns​

System.Type

Parameters​
TypeName
System.Typetype
System.Type[]genericTypeDefinitions

IsOrHasGenericInterfaceTypeOf(Type, Type)​

View Source​
Declaration
public static bool IsOrHasGenericInterfaceTypeOf(this Type type, Type genericTypeDefinition)
Returns​

System.Boolean

Parameters​
TypeName
System.Typetype
System.TypegenericTypeDefinition

GetTypeWithGenericTypeDefinitionOf(Type, Type)​

View Source​
Declaration
public static Type GetTypeWithGenericTypeDefinitionOf(this Type type, Type genericTypeDefinition)
Returns​

System.Type

Parameters​
TypeName
System.Typetype
System.TypegenericTypeDefinition

FirstGenericArg(Type)​

View Source​
Declaration
public static Type FirstGenericArg(this Type type)
Returns​

System.Type

Parameters​
TypeName
System.Typetype

GetTypeWithInterfaceOf(Type, Type)​

View Source​
Declaration
public static Type GetTypeWithInterfaceOf(this Type type, Type interfaceType)
Returns​

System.Type

Parameters​
TypeName
System.Typetype
System.TypeinterfaceType

HasInterface(Type, Type)​

View Source​
Declaration
public static bool HasInterface(this Type type, Type interfaceType)
Returns​

System.Boolean

Parameters​
TypeName
System.Typetype
System.TypeinterfaceType

HasAnyInterface(Type, Type[])​

View Source​
Declaration
public static bool HasAnyInterface(this Type type, Type[] interfaceTypes)
Returns​

System.Boolean

Parameters​
TypeName
System.Typetype
System.Type[]interfaceTypes

AllHaveInterfacesOfType(Type, Type[])​

View Source​
Declaration
public static bool AllHaveInterfacesOfType(this Type assignableFromType, params Type[] types)
Returns​

System.Boolean

Parameters​
TypeName
System.TypeassignableFromType
System.Type[]types

IsNullableType(Type)​

View Source​
Declaration
public static bool IsNullableType(this Type type)
Returns​

System.Boolean

Parameters​
TypeName
System.Typetype

GetUnderlyingTypeCode(Type)​

View Source​
Declaration
public static TypeCode GetUnderlyingTypeCode(this Type type)
Returns​

System.TypeCode

Parameters​
TypeName
System.Typetype

IsNumericType(Type)​

View Source​
Declaration
public static bool IsNumericType(this Type type)
Returns​

System.Boolean

Parameters​
TypeName
System.Typetype

IsIntegerType(Type)​

View Source​
Declaration
public static bool IsIntegerType(this Type type)
Returns​

System.Boolean

Parameters​
TypeName
System.Typetype

IsRealNumberType(Type)​

View Source​
Declaration
public static bool IsRealNumberType(this Type type)
Returns​

System.Boolean

Parameters​
TypeName
System.Typetype

GetTypeWithGenericInterfaceOf(Type, Type)​

View Source​
Declaration
public static Type GetTypeWithGenericInterfaceOf(this Type type, Type genericInterfaceType)
Returns​

System.Type

Parameters​
TypeName
System.Typetype
System.TypegenericInterfaceType

HasAnyTypeDefinitionsOf(Type, Type[])​

View Source​
Declaration
public static bool HasAnyTypeDefinitionsOf(this Type genericType, params Type[] theseGenericTypes)
Returns​

System.Boolean

Parameters​
TypeName
System.TypegenericType
System.Type[]theseGenericTypes

GetGenericArgumentsIfBothHaveSameGenericDefinitionTypeAndArguments(Type, Type, Type)​

View Source​
Declaration
public static Type[] GetGenericArgumentsIfBothHaveSameGenericDefinitionTypeAndArguments(this Type assignableFromType, Type typeA, Type typeB)
Returns​

System.Type[]

Parameters​
TypeName
System.TypeassignableFromType
System.TypetypeA
System.TypetypeB

GetGenericArgumentsIfBothHaveConvertibleGenericDefinitionTypeAndArguments(Type, Type, Type)​

View Source​
Declaration
public static TypePair GetGenericArgumentsIfBothHaveConvertibleGenericDefinitionTypeAndArguments(this Type assignableFromType, Type typeA, Type typeB)
Returns​

ServiceStack.Text.Support.TypePair

Parameters​
TypeName
System.TypeassignableFromType
System.TypetypeA
System.TypetypeB

AreAllStringOrValueTypes(Type[])​

View Source​
Declaration
public static bool AreAllStringOrValueTypes(params Type[] types)
Returns​

System.Boolean

Parameters​
TypeName
System.Type[]types

GetConstructorMethod(Type)​

View Source​
Declaration
public static EmptyCtorDelegate GetConstructorMethod(Type type)
Returns​

ServiceStack.EmptyCtorDelegate

Parameters​
TypeName
System.Typetype

GetConstructorMethod(String)​

View Source​
Declaration
public static EmptyCtorDelegate GetConstructorMethod(string typeName)
Returns​

ServiceStack.EmptyCtorDelegate

Parameters​
TypeName
System.StringtypeName

GetConstructorMethodToCache(Type)​

View Source​
Declaration
public static EmptyCtorDelegate GetConstructorMethodToCache(Type type)
Returns​

ServiceStack.EmptyCtorDelegate

Parameters​
TypeName
System.Typetype

CreateInstance<T>()​

View Source​
Declaration
public static object CreateInstance<T>()
Returns​

System.Object

Type Parameters​
  • T

New<T>(Type)​

Creates a new instance of type. First looks at JsConfig.ModelFactory before falling back to CreateInstance

View Source​
Declaration
public static T New<T>(this Type type)
Returns​

<T>

Parameters​
TypeName
System.Typetype
Type Parameters​
  • T

New(Type)​

Creates a new instance of type. First looks at JsConfig.ModelFactory before falling back to CreateInstance

View Source​
Declaration
public static object New(this Type type)
Returns​

System.Object

Parameters​
TypeName
System.Typetype

CreateInstance(Type)​

Creates a new instance from the default constructor of type

View Source​
Declaration
public static object CreateInstance(this Type type)
Returns​

System.Object

Parameters​
TypeName
System.Typetype

CreateInstance<T>(Type)​

View Source​
Declaration
public static T CreateInstance<T>(this Type type)
Returns​

<T>

Parameters​
TypeName
System.Typetype
Type Parameters​
  • T

CreateInstance(String)​

View Source​
Declaration
public static object CreateInstance(string typeName)
Returns​

System.Object

Parameters​
TypeName
System.StringtypeName

GetModule(Type)​

View Source​
Declaration
public static Module GetModule(this Type type)
Returns​

System.Reflection.Module

Parameters​
TypeName
System.Typetype

GetAllProperties(Type)​

View Source​
Declaration
public static PropertyInfo[] GetAllProperties(this Type type)
Returns​

System.Reflection.PropertyInfo[]

Parameters​
TypeName
System.Typetype

GetPublicProperties(Type)​

View Source​
Declaration
public static PropertyInfo[] GetPublicProperties(this Type type)
Returns​

System.Reflection.PropertyInfo[]

Parameters​
TypeName
System.Typetype

GetAllSerializableProperties(Type)​

Includes unfiltered serializable properties suitable for caching. Need to exclude JsConfig.ShouldExcludePropertyType() if serializing at runtime

View Source​
Declaration
public static PropertyInfo[] GetAllSerializableProperties(this Type type)
Returns​

System.Reflection.PropertyInfo[]

Parameters​
TypeName
System.Typetype

GetSerializableProperties(Type)​

View Source​
Declaration
public static PropertyInfo[] GetSerializableProperties(this Type type)
Returns​

System.Reflection.PropertyInfo[]

Parameters​
TypeName
System.Typetype

OnlySerializableProperties(PropertyInfo[], Type)​

View Source​
Declaration
public static PropertyInfo[] OnlySerializableProperties(this PropertyInfo[] properties, Type type = null)
Returns​

System.Reflection.PropertyInfo[]

Parameters​
TypeName
System.Reflection.PropertyInfo[]properties
System.Typetype

GetOnDeserializing<T>()​

View Source​
Declaration
public static Func<object, string, object, object> GetOnDeserializing<T>()
Returns​

System.Func<System.Object,System.String,System.Object,System.Object>

Type Parameters​
  • T

GetSerializableFields(Type)​

View Source​
Declaration
public static FieldInfo[] GetSerializableFields(this Type type)
Returns​

System.Reflection.FieldInfo[]

Parameters​
TypeName
System.Typetype

GetDataContract(Type)​

View Source​
Declaration
public static DataContractAttribute GetDataContract(this Type type)
Returns​

System.Runtime.Serialization.DataContractAttribute

Parameters​
TypeName
System.Typetype

GetDataMember(PropertyInfo)​

View Source​
Declaration
public static DataMemberAttribute GetDataMember(this PropertyInfo pi)
Returns​

System.Runtime.Serialization.DataMemberAttribute

Parameters​
TypeName
System.Reflection.PropertyInfopi

GetDataMember(FieldInfo)​

View Source​
Declaration
public static DataMemberAttribute GetDataMember(this FieldInfo pi)
Returns​

System.Runtime.Serialization.DataMemberAttribute

Parameters​
TypeName
System.Reflection.FieldInfopi

GetDataMemberName(PropertyInfo)​

View Source​
Declaration
public static string GetDataMemberName(this PropertyInfo pi)
Returns​

System.String

Parameters​
TypeName
System.Reflection.PropertyInfopi

GetDataMemberName(FieldInfo)​

View Source​
Declaration
public static string GetDataMemberName(this FieldInfo fi)
Returns​

System.String

Parameters​
TypeName
System.Reflection.FieldInfofi