@@ -15,18 +15,7 @@ internal static CodeTypeReference CreateCodeTypeReference(this TypeReference typ
1515 private static CodeTypeReference CreateCodeTypeReferenceWithNullabilityMap ( TypeReference type , IEnumerator < bool ? > nullabilityMap , NullableMode mode , bool disableNested )
1616 {
1717 var typeName = GetTypeName ( type , nullabilityMap , mode , disableNested ) ;
18- if ( type . IsValueType && type . Name == "Nullable`1" && type . Namespace == "System" )
19- {
20- // unwrap System.Nullable<Type> into Type? for readability
21- var genericArgs = type is IGenericInstance instance
22- ? instance . GenericArguments
23- : type . HasGenericParameters ? type . GenericParameters . Cast < TypeReference > ( ) : throw new NotSupportedException ( type . ToString ( ) ) ;
24- return CreateCodeTypeReferenceWithNullabilityMap ( genericArgs . Single ( ) , nullabilityMap , NullableMode . Force , disableNested ) ;
25- }
26- else
27- {
28- return new CodeTypeReference ( typeName , CreateGenericArguments ( type , nullabilityMap ) ) ;
29- }
18+ return new CodeTypeReference ( typeName , CreateGenericArguments ( type , nullabilityMap ) ) ;
3019 }
3120
3221 private static CodeTypeReference [ ] CreateGenericArguments ( TypeReference type , IEnumerator < bool ? > nullabilityMap )
@@ -86,7 +75,7 @@ private static CodeTypeReference[] CreateGenericArguments(TypeReference type, IE
8675
8776 // The compiler optimizes the size of metadata bypassing a sequence of bytes for value types.
8877 // Thus, it can even delete the entire NullableAttribute if the whole signature consists only of value types,
89- // for example KeyValuePair<int, int?>, thus we can call IsNullable() only by looking first deep into the signature
78+ // for example KeyValuePair<int, int?>, thus we can call IsNullable() only by looking first deep into the signature.
9079 private static bool HasAnyReferenceType ( TypeReference type )
9180 {
9281 if ( ! type . IsValueType )
@@ -107,7 +96,11 @@ private static bool HasAnyReferenceType(TypeReference type)
10796
10897 private static string GetTypeName ( TypeReference type , IEnumerator < bool ? > ? nullabilityMap , NullableMode mode , bool disableNested )
10998 {
110- bool nullable = mode != NullableMode . Disable && ( mode == NullableMode . Force || HasAnyReferenceType ( type ) && IsNullable ( ) ) ;
99+ bool nullable =
100+ mode != NullableMode . Disable &&
101+ ! ( type . Namespace == "System" && type . Name == "Nullable`1" ) &&
102+ HasAnyReferenceType ( type ) &&
103+ IsNullable ( ) ; // we should not touch nullabilityMap enumerator in the above cases
111104
112105 var typeName = GetTypeNameCore ( type , nullabilityMap , nullable , disableNested ) ;
113106
0 commit comments