admin管理员组文章数量:1399953
I have the following function:
protected bool IsNullableParam(string name, Type type)
{
bool isNullable;
Type? realType = Nullable.GetUnderlyingType(type);
if (realType != null)
{
isNullable = false;
}
else
{
isNullable = true;
}
return isNullable;
}
...
...
string? s = "test";
ParameterSchema("name", s.GetType());
....
When I call it like in the example isNullable will be set to false. I know from other posts that GetUnderlyingType doesn't work to check nullability of a string and I've seen a few solutions in case of PropertyInfo and FieldInfo but I couldn't find a solution when Type is used. In my case I have only a Type instance. Is there a workaround to determine via reflection if a string is nullable ?
本文标签: netCheck if a string is nullable from Type in CStack Overflow
版权声明:本文标题:.net - Check if a string is nullable from Type in C# - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744148843a2592967.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论