@@ -92,6 +92,11 @@ public class RootCommandImplementation {
9292 description : "Generates member declarations in the order of the static members first." ,
9393 getDefaultValue : static ( ) => false
9494 ) ;
95+ private static readonly Option < bool > optionGenerateNullableAnnotations = new (
96+ aliases : new [ ] { "--generate-nullableanotations" } ,
97+ description : "Generates declarations with nullable annotations." ,
98+ getDefaultValue : static ( ) => true
99+ ) ;
95100
96101 private readonly IServiceProvider ? serviceProvider ;
97102 private readonly Microsoft . Extensions . Logging . ILogger ? logger ;
@@ -118,6 +123,7 @@ internal Command CreateCommand()
118123 optionGenerateFullTypeName ,
119124 optionGenerateMethodBody ,
120125 optionGenerateStaticMembersFirst ,
126+ optionGenerateNullableAnnotations ,
121127 } ;
122128
123129 rootCommand . Handler = CommandHandler . Create < ParseResult , IConsole > ( CommandMain ) ;
@@ -141,9 +147,13 @@ private static ApiListWriterOptions GetApiListWriterOptions(ParseResult parseRes
141147 options . MemberDeclaration . WithNamespace = parseResult . ValueForOption ( optionGenerateFullTypeName ) ;
142148 options . AttributeDeclaration . WithNamespace = parseResult . ValueForOption ( optionGenerateFullTypeName ) ;
143149
144- options . MemberDeclaration . MethodBody = parseResult . ValueForOption ( optionGenerateMethodBody ) ;
150+ var methodBody = parseResult . ValueForOption ( optionGenerateMethodBody ) ;
151+
152+ options . MemberDeclaration . MethodBody = methodBody ;
153+ options . MemberDeclaration . AccessorBody = methodBody ;
145154
146- options . Writer . OrderStaticMembersFirst = parseResult . ValueForOption ( optionGenerateStaticMembersFirst ) ;
155+ options . Writer . OrderStaticMembersFirst = parseResult . ValueForOption ( optionGenerateStaticMembersFirst ) ;
156+ options . Writer . WriteNullableAnnotationDirective = parseResult . ValueForOption ( optionGenerateNullableAnnotations ) ;
147157
148158 options . AttributeDeclaration . TypeFilter = AttributeFilter . Default ;
149159
@@ -170,20 +180,28 @@ private void CommandMain(ParseResult parseResult, IConsole console)
170180 var options = GetApiListWriterOptions ( parseResult ) ;
171181 var outputDirectory = GetOutputDirectory ( parseResult ) ;
172182 var loadAssemblyIntoReflectionOnlyContext = parseResult . ValueForOption ( optionLoadAssemblyIntoReflectionOnlyContext ) ;
183+ var enableNullabilityAnnotations = parseResult . ValueForOption ( optionGenerateNullableAnnotations ) ;
173184
174185 foreach ( var inputAssemblyFile in GetInputAssemblyFiles ( parseResult ) ) {
175186 AssemblyLoader . UsingAssembly (
176187 inputAssemblyFile ,
177- arg : ( outputDirectory , options , logger ) ,
188+ arg : (
189+ outputDirectory ,
190+ options ,
191+ enableNullabilityAnnotations ,
192+ logger
193+ ) ,
178194 logger : logger ,
179195 context : out var context ,
180196 loadIntoReflectionOnlyContext : loadAssemblyIntoReflectionOnlyContext ,
181197 actionWithLoadedAssembly : static ( assm , arg ) => {
182198 try {
183199#if SYSTEM_REFLECTION_NULLABILITYINFOCONTEXT
184- // assign NullabilityInfoContext to each assembly
185- var nullabilityInfoContext = new NullabilityInfoContext ( ) ;
200+ var nullabilityInfoContext = arg . enableNullabilityAnnotations
201+ ? new NullabilityInfoContext ( )
202+ : null ;
186203
204+ // assign NullabilityInfoContext to each assembly
187205 arg . options . TypeDeclaration . NullabilityInfoContext = nullabilityInfoContext ;
188206 arg . options . MemberDeclaration . NullabilityInfoContext = nullabilityInfoContext ;
189207#endif
0 commit comments