@@ -203,88 +203,50 @@ public override bool Execute(out IList<Exception> thrownExceptions)
203203
204204 using ( var assemblyDefinition = AssemblyDefinition . ReadAssembly ( IOPath . GetFullPath ( Assembly ) , readerParameters ) )
205205 {
206- CustomAttribute xamlProcessingAttr = null ;
207- if ( assemblyDefinition . HasCustomAttributes &&
208- ( xamlProcessingAttr =
209- assemblyDefinition . CustomAttributes . FirstOrDefault (
210- ca => ca . AttributeType . FullName == "Microsoft.Maui.Controls.Xaml.XamlProcessingAttribute" ) ) != null )
211- {
212- var inflator = ( XamlInflator ) xamlProcessingAttr . ConstructorArguments [ 0 ] . Value ;
213- var generateInflatorSwitch = xamlProcessingAttr . ConstructorArguments . Count > 1
214- && ( bool ) xamlProcessingAttr . ConstructorArguments [ 1 ] . Value ;
215- assemblyInflatorOptions = ( generateInflatorSwitch , inflator ) ;
216- if ( ! generateInflatorSwitch )
217- skipassembly = ( inflator & XamlInflator . XamlC ) != XamlInflator . XamlC && inflator != XamlInflator . Default ;
218-
219- }
220-
221- #pragma warning disable CS0618 // Type or member is obsolete
206+ #if _MAUIXAML_SOURCEGEN_BACKCOMPAT
222207 CustomAttribute xamlcAttr = null ;
223208 if ( assemblyDefinition . HasCustomAttributes &&
224209 ( xamlcAttr =
225210 assemblyDefinition . CustomAttributes . FirstOrDefault (
226211 ca => ca . AttributeType . FullName == "Microsoft.Maui.Controls.Xaml.XamlCompilationAttribute" ) ) != null )
227212 {
228- if ( xamlProcessingAttr == null )
229- {
230- var options = ( XamlCompilationOptions ) xamlcAttr . ConstructorArguments [ 0 ] . Value ;
231- if ( ( options & XamlCompilationOptions . Skip ) == XamlCompilationOptions . Skip )
232- skipassembly = true ;
233- if ( ( options & XamlCompilationOptions . Compile ) == XamlCompilationOptions . Compile )
234- skipassembly = false ;
235- }
236- else
237- LoggingHelper . LogWarning ( $ "{ new string ( ' ' , 2 ) } Assembly has both XamlCompilationAttribute and XamlProcessingAttribute. XamlCompilationAttribute will be ignored.") ;
213+ var options = ( XamlCompilationOptions ) xamlcAttr . ConstructorArguments [ 0 ] . Value ;
214+ if ( ( options & XamlCompilationOptions . Skip ) == XamlCompilationOptions . Skip )
215+ skipassembly = true ;
216+ if ( ( options & XamlCompilationOptions . Compile ) == XamlCompilationOptions . Compile )
217+ skipassembly = false ;
238218 }
239- #pragma warning restore CS0618 // Type or member is obsolete
240219
241- xamlcAttr = xamlProcessingAttr = null ;
220+ xamlcAttr = null ;
221+ #endif
242222
243223 foreach ( var module in assemblyDefinition . Modules )
244224 {
245225 var skipmodule = skipassembly ;
246226 ( bool , XamlInflator ) ? moduleInflatorOptions = assemblyInflatorOptions ;
247227
248- if ( module . HasCustomAttributes &&
249- ( xamlProcessingAttr =
250- module . CustomAttributes . FirstOrDefault (
251- ca => ca . AttributeType . FullName == "Microsoft.Maui.Controls.Xaml.XamlProcessingAttribute" ) ) != null )
252- {
253- var inflator = ( XamlInflator ) xamlProcessingAttr . ConstructorArguments [ 0 ] . Value ;
254- var generateInflatorSwitch = xamlProcessingAttr . ConstructorArguments . Count > 1
255- && ( bool ) xamlProcessingAttr . ConstructorArguments [ 1 ] . Value ;
256- moduleInflatorOptions = ( generateInflatorSwitch , inflator ) ;
257- if ( ! generateInflatorSwitch )
258- skipmodule = ( inflator & XamlInflator . XamlC ) != XamlInflator . XamlC && inflator != XamlInflator . Default ;
259- }
260-
261- #pragma warning disable CS0618 // Type or member is obsolete
228+ #if _MAUIXAML_SOURCEGEN_BACKCOMPAT
262229 if ( module . HasCustomAttributes &&
263230 ( xamlcAttr =
264231 module . CustomAttributes . FirstOrDefault (
265232 ca => ca . AttributeType . FullName == "Microsoft.Maui.Controls.Xaml.XamlCompilationAttribute" ) ) != null )
266233 {
267- if ( xamlProcessingAttr == null )
268- {
269-
270- var options = ( XamlCompilationOptions ) xamlcAttr . ConstructorArguments [ 0 ] . Value ;
271- if ( ( options & XamlCompilationOptions . Skip ) == XamlCompilationOptions . Skip )
272- skipmodule = true ;
273- if ( ( options & XamlCompilationOptions . Compile ) == XamlCompilationOptions . Compile )
274- skipmodule = false ;
275- }
276- else
277- LoggingHelper . LogWarning ( $ "{ new string ( ' ' , 2 ) } Module { module . Name } has both XamlCompilationAttribute and XamlProcessingAttribute. XamlCompilationAttribute will be ignored.") ;
234+ var options = ( XamlCompilationOptions ) xamlcAttr . ConstructorArguments [ 0 ] . Value ;
235+ if ( ( options & XamlCompilationOptions . Skip ) == XamlCompilationOptions . Skip )
236+ skipmodule = true ;
237+ if ( ( options & XamlCompilationOptions . Compile ) == XamlCompilationOptions . Compile )
238+ skipmodule = false ;
278239 }
279- #pragma warning restore CS0618 // Type or member is obsolete
280-
281- xamlcAttr = xamlProcessingAttr = null ;
240+ xamlcAttr = null ;
241+ #endif
282242
283243 LoggingHelper . LogMessage ( Low , $ "{ new string ( ' ' , 2 ) } Module: { module . Name } ") ;
284244 var resourcesToPrune = new List < EmbeddedResource > ( ) ;
285245 foreach ( var resource in module . Resources . OfType < EmbeddedResource > ( ) )
286246 {
287- var initCompName = "InitializeComponent" ;
247+ var generateInflatorSwitch = module . Assembly . Name . Name == "Microsoft.Maui.Controls.Xaml.UnitTests" ;
248+ var initCompName = generateInflatorSwitch ? "InitializeComponentXamlC" : "InitializeComponent" ;
249+
288250 LoggingHelper . LogMessage ( Low , $ "{ new string ( ' ' , 4 ) } Resource: { resource . Name } ") ;
289251 string classname ;
290252 if ( ! resource . IsXaml ( cache , module , out classname ) )
@@ -301,53 +263,27 @@ public override bool Execute(out IList<Exception> thrownExceptions)
301263 var skiptype = skipmodule ;
302264 ( bool , XamlInflator ) ? typeInflatorOptions = moduleInflatorOptions ;
303265
304- if ( typeDef . HasCustomAttributes &&
305- ( xamlProcessingAttr =
306- typeDef . CustomAttributes . FirstOrDefault (
307- ca => ca . AttributeType . FullName == "Microsoft.Maui.Controls.Xaml.XamlProcessingAttribute" ) ) != null )
308- {
309- var inflator = ( XamlInflator ) xamlProcessingAttr . ConstructorArguments [ 0 ] . Value ;
310- var generateInflatorSwitch = xamlProcessingAttr . ConstructorArguments . Count > 1
311- && ( bool ) xamlProcessingAttr . ConstructorArguments [ 1 ] . Value ;
312-
313- typeInflatorOptions = ( generateInflatorSwitch , inflator ) ;
314- if ( generateInflatorSwitch )
315- {
316- skiptype = ( inflator & XamlInflator . XamlC ) != XamlInflator . XamlC && inflator != XamlInflator . Default ;
317- initCompName = "InitializeComponentXamlC" ;
318- }
319- else
320- skiptype = inflator != XamlInflator . XamlC ;
321- }
322- #pragma warning disable CS0618 // Type or member is obsolete
266+ #if _MAUIXAML_SOURCEGEN_BACKCOMPAT
323267 if ( typeDef . HasCustomAttributes &&
324268 ( xamlcAttr =
325269 typeDef . CustomAttributes . FirstOrDefault (
326270 ca => ca . AttributeType . FullName == "Microsoft.Maui.Controls.Xaml.XamlCompilationAttribute" ) ) != null )
327271 {
328- if ( xamlProcessingAttr == null )
329- {
330- // XamlCompilationAttribute is obsolete, but we still need to support it
331- // for backwards compatibility
332- var options = ( XamlCompilationOptions ) xamlcAttr . ConstructorArguments [ 0 ] . Value ;
333- if ( ( options & XamlCompilationOptions . Skip ) == XamlCompilationOptions . Skip )
334- skiptype = true ;
335- if ( ( options & XamlCompilationOptions . Compile ) == XamlCompilationOptions . Compile )
336- skiptype = false ;
337- }
338- else
339- LoggingHelper . LogWarning ( $ "{ new string ( ' ' , 6 ) } Type { typeDef . Name } has both XamlCompilationAttribute and XamlProcessingAttribute. XamlCompilationAttribute will be ignored.") ;
272+ var options = ( XamlCompilationOptions ) xamlcAttr . ConstructorArguments [ 0 ] . Value ;
273+ if ( ( options & XamlCompilationOptions . Skip ) == XamlCompilationOptions . Skip )
274+ skiptype = true ;
275+ if ( ( options & XamlCompilationOptions . Compile ) == XamlCompilationOptions . Compile )
276+ skiptype = false ;
340277 }
341- #pragma warning restore CS0618 // Type or member is obsolete
342-
343- xamlcAttr = xamlProcessingAttr = null ;
278+ xamlcAttr = null ;
279+ #endif
344280
345281 if ( Type != null )
346282 skiptype = ! ( Type == classname ) ;
347283
348284 if ( skiptype && ! ForceCompile )
349285 {
350- LoggingHelper . LogMessage ( Low , $ "{ new string ( ' ' , 6 ) } has XamlCompilation or XamlProceesing disabling XamlC... skipped.") ;
286+ LoggingHelper . LogMessage ( Low , $ "{ new string ( ' ' , 6 ) } has XamlCompilation disabling XamlC... skipped.") ;
351287 continue ;
352288 }
353289
0 commit comments