@@ -35,7 +35,8 @@ internal enum DeclarationModifiers
35
35
{
36
36
None ,
37
37
AsSpan ,
38
- LongCast
38
+ LongCast ,
39
+ AllowNullConditionalOperator ,
39
40
}
40
41
41
42
// Contains all information about a loggable member
@@ -46,16 +47,35 @@ internal static class LoggableMemberExtensions
46
47
private static ( DeclarationType , DeclarationModifiers ) ? GetDeclarationType ( this ITypeSymbol typeSymbol , LogAttributeInfo attributeInfo , CancellationToken token )
47
48
{
48
49
token . ThrowIfCancellationRequested ( ) ;
50
+
51
+ var modifiers = DeclarationModifiers . None ;
52
+
53
+ if ( typeSymbol . IsReferenceType )
54
+ {
55
+ modifiers = DeclarationModifiers . AllowNullConditionalOperator ;
56
+ }
57
+ else if ( typeSymbol . OriginalDefinition . SpecialType == SpecialType . System_Nullable_T )
58
+ {
59
+ // Pull out the inner type
60
+ var namedTypeSymbol = ( INamedTypeSymbol ) typeSymbol ;
61
+ var innerType = namedTypeSymbol . TypeArguments [ 0 ] ;
62
+ typeSymbol = innerType ;
63
+
64
+ modifiers = DeclarationModifiers . AllowNullConditionalOperator ;
65
+ }
66
+
67
+ token . ThrowIfCancellationRequested ( ) ;
68
+
49
69
// If we know we're generating a loggable implementation
50
70
if ( typeSymbol . GetAttributes ( ) . Where ( x => x . AttributeClass ? . ToDisplayString ( ) == "Stereologue.GenerateLogAttribute" ) . Any ( ) )
51
71
{
52
- return ( DeclarationType . Logged , DeclarationModifiers . None ) ;
72
+ return ( DeclarationType . Logged , modifiers ) ;
53
73
}
54
74
token . ThrowIfCancellationRequested ( ) ;
55
75
// If we know we already implement ILogged
56
76
if ( typeSymbol . AllInterfaces . Where ( x => x . ToDisplayString ( ) == "Stereologue.ILogged" ) . Any ( ) )
57
77
{
58
- return ( DeclarationType . Logged , DeclarationModifiers . None ) ;
78
+ return ( DeclarationType . Logged , modifiers ) ;
59
79
}
60
80
token . ThrowIfCancellationRequested ( ) ;
61
81
// If we have an UpdateMonologue function
@@ -79,7 +99,7 @@ private static (DeclarationType, DeclarationModifiers)? GetDeclarationType(this
79
99
}
80
100
if ( parameters [ 0 ] . Type . SpecialType == SpecialType . System_String && parameters [ 1 ] . Type . ToDisplayString ( ) == "Stereologue.Stereologuer" )
81
101
{
82
- return ( DeclarationType . Logged , DeclarationModifiers . None ) ;
102
+ return ( DeclarationType . Logged , modifiers ) ;
83
103
}
84
104
}
85
105
}
0 commit comments