提交 89849ea3 编写于 作者: S Sam Harwell

Simplify IsMutableValueType and eliminate recursion

上级 1730043b
......@@ -857,6 +857,13 @@ public static bool IsEnumType(this ITypeSymbol type)
public static bool? IsMutableValueType(this ITypeSymbol type)
{
if (type.IsNullable())
{
// Nullable<T> can only be mutable if T is mutable. This case ensures types like 'int?' are treated as
// immutable.
type = type.GetTypeArguments()[0];
}
if (type.IsErrorType())
{
return null;
......@@ -867,26 +874,6 @@ public static bool IsEnumType(this ITypeSymbol type)
return false;
}
if (type.IsNullable())
{
// Nullable<T> can only be mutable if T is mutable. This case ensures types like 'int?' are treated as
// immutable.
var typeArguments = type.GetTypeArguments();
if (typeArguments.Length != 1)
{
return null;
}
if (typeArguments[0].IsNullable())
{
// Recursion prevention. This is not a valid type anyway since the T in Nullable<T> cannot itself be
// nullable.
return null;
}
return typeArguments[0].IsMutableValueType();
}
foreach (var member in type.GetMembers())
{
if (member is IFieldSymbol fieldSymbol &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册