How to represent this VB?
t开发者_开发技巧ypeof(Nullable<>)
public static bool IsNullableType(Type t)
{
return t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Nullable<>);
}
I was using this to check whether Lambda Expressioin parameters are nullable.
There's no need to do this yourself - you can just use Nullable.GetUnderlyingType
which returns Nothing
/null
if the type you pass it isn't nullable:
Public Shared Function IsNullable(t as Type) As Boolean
Return Nullable.GetUnderlyingType(t) IsNot Nothing
End Function
(But if you really need an open generic type, then GetType(Nullable(Of))
will work. If you need multiple type parameters, just comma-separate them, e.g. GetType(Dictionary(Of ,))
.)
(t.GetGenericTypeDefinition() Is GetType(Nullable(Of )))
Public Shared Function IsNullableType(t As Type) As Boolean
Return t.IsGenericType AndAlso t.GetGenericTypeDefinition() = GetType(Nullable(Of ))
End Function
Used the following free tool to convert: http://www.developerfusion.com/tools/convert/csharp-to-vb/
精彩评论