Open sandboxFocus

Method ToNonNullableType

ToNonNullableType(IType)

Returns the non-nullable type from the current IType. If the current type is a non-nullable reference type, returns the current type. If the current type is a Nullable<T>, i.e. a nullable value type, returns the underlying type.

Declaration
public static IType ToNonNullableType(this IType type)
Parameters
Type Name Description
IType type
Returns
Type Description
IType
Remarks

Note that for non-value type type parameters, this method strips the nullable annotation, if any, which means it returns a type whose IsNullable property returns null. This is because C# has no way to express non-nullability for type parameters.

ToNonNullableType(ITypeParameter)

Returns the non-nullable type from the current ITypeParameter. If the current type is a non-nullable reference type, returns the current type.

Declaration
public static ITypeParameter ToNonNullableType(this ITypeParameter type)
Parameters
Type Name Description
ITypeParameter type
Returns
Type Description
ITypeParameter
Remarks

Note that for non-value type type parameters, this method strips the nullable annotation, if any, which means it returns a type whose IsNullable property returns null. This is because C# has no way to express non-nullability for type parameters.

ToNonNullableType(IArrayType)

Returns the non-nullable type from the current IArrayType. If the current type is non-nullable, returns the current type.

Declaration
public static IArrayType ToNonNullableType(this IArrayType type)
Parameters
Type Name Description
IArrayType type
Returns
Type Description
IArrayType

ToNonNullableType(IDynamicType)

Returns the non-nullable type from the current IDynamicType. If the current type is non-nullable, returns the current type.

Declaration
public static IDynamicType ToNonNullableType(this IDynamicType type)
Parameters
Type Name Description
IDynamicType type
Returns
Type Description
IDynamicType

ToNonNullableType(INamedType)

Returns the non-nullable type from the current INamedType. If the current type is a non-nullable reference type, returns the current type. If current type represents a Nullable<T> where T is a value-type type parameter, this method returns ITypeParameter. Otherwise, it returns an INamedType.

Declaration
public static IType ToNonNullableType(this INamedType type)
Parameters
Type Name Description
INamedType type
Returns
Type Description
IType