@@ -247,7 +247,11 @@ static SyntaxFixupType GetSyntaxFixupType(AvailableType availableType, Generatio
247247 // Combine the syntax type with any analyzer options
248248 SyntaxFixupType fixupType = info . AvailableType . FixupType | GetSyntaxFixupType ( info . AvailableType , info . Options ) ;
249249
250- return new ( info . AvailableType . FullyQualifiedMetadataName , info . Options . UsePublicAccessibilityForGeneratedTypes , fixupType ) ;
250+ // Also combine additional flags from project settings
251+ fixupType |= info . Options . UsePublicAccessibilityForGeneratedTypes ? SyntaxFixupType . UsePublicAccessibilityModifier : SyntaxFixupType . None ;
252+ fixupType |= ! info . Options . UseEmbeddedAttributeForGeneratedTypes ? SyntaxFixupType . RemoveEmbeddedAttributes : SyntaxFixupType . None ;
253+
254+ return new ( info . AvailableType . FullyQualifiedMetadataName , fixupType ) ;
251255 }
252256
253257 /// <summary>
@@ -285,8 +289,8 @@ private void EmitGeneratedType(SourceProductionContext context, GeneratedType ty
285289
286290 using Stream stream = typeof ( PolyfillsGenerator ) . Assembly . GetManifestResourceStream ( resourceName ) ;
287291
288- // If public accessibility has been requested or a syntax fixup is needed, we need to update the loaded source files
289- if ( type is { IsPublicAccessibilityRequired : true } or { FixupType : not SyntaxFixupType . None } )
292+ // If a syntax fixup is needed, we need to update the loaded source files
293+ if ( type is { FixupType : not SyntaxFixupType . None } )
290294 {
291295 string adjustedSource ;
292296
@@ -295,7 +299,7 @@ private void EmitGeneratedType(SourceProductionContext context, GeneratedType ty
295299 adjustedSource = reader . ReadToEnd ( ) ;
296300 }
297301
298- if ( type . IsPublicAccessibilityRequired )
302+ if ( ( type . FixupType & SyntaxFixupType . UsePublicAccessibilityModifier ) != 0 )
299303 {
300304 // After reading the file, replace all internal keywords with public. Use a space before and after the identifier
301305 // to avoid potential false positives. This could also be done by loading the source tree and using a syntax
@@ -306,6 +310,12 @@ private void EmitGeneratedType(SourceProductionContext context, GeneratedType ty
306310 // If types are public, we also need to strip the '[Embedded]' attributes, as it's not allowed on public types
307311 adjustedSource = EmbeddedAttributeRegex . Replace ( adjustedSource , "" ) ;
308312 }
313+ else if ( ( type . FixupType & SyntaxFixupType . RemoveEmbeddedAttributes ) != 0 )
314+ {
315+ // Remove the '[Embedded]' attributes as above, if requested. We only need this check if types
316+ // are not public, or these attributes would've already been stripped by the previous branch.
317+ adjustedSource = EmbeddedAttributeRegex . Replace ( adjustedSource , "" ) ;
318+ }
309319
310320 if ( ( type . FixupType & SyntaxFixupType . RemoveMethodImplAttributes ) != 0 )
311321 {
@@ -344,7 +354,7 @@ namespace System.Runtime.CompilerServices2
344354 }
345355 else
346356 {
347- // If the default accessibility is used , we can load the source directly
357+ // Otherwise if no fixups are needed , we can load the source directly
348358 sourceText = SourceText . From ( stream , Encoding . UTF8 , canBeEmbedded : true ) ;
349359 }
350360
0 commit comments