@@ -1397,16 +1397,7 @@ EntityDeclaration DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun
13971397 }
13981398 if ( settings . IntroduceRefModifiersOnStructs )
13991399 {
1400- if ( FindAttribute ( typeDecl , KnownAttribute . Obsolete , out var attr ) )
1401- {
1402- if ( obsoleteAttributePattern . IsMatch ( attr ) )
1403- {
1404- if ( attr . Parent is AttributeSection section && section . Attributes . Count == 1 )
1405- section . Remove ( ) ;
1406- else
1407- attr . Remove ( ) ;
1408- }
1409- }
1400+ RemoveObsoleteAttribute ( typeDecl , "Types with embedded references are not supported in this version of your compiler." ) ;
14101401 RemoveCompilerFeatureRequiredAttribute ( typeDecl , "RefStructs" ) ;
14111402 }
14121403 if ( settings . RequiredMembers )
@@ -1584,14 +1575,6 @@ EnumValueDisplayMode DetectBestEnumValueDisplayMode(ITypeDefinition typeDef, PEF
15841575 return firstValue == 0 ? EnumValueDisplayMode . None : EnumValueDisplayMode . FirstOnly ;
15851576 }
15861577
1587- static readonly Syntax . Attribute obsoleteAttributePattern = new Syntax . Attribute ( ) {
1588- Type = new TypePattern ( typeof ( ObsoleteAttribute ) ) ,
1589- Arguments = {
1590- new PrimitiveExpression ( "Types with embedded references are not supported in this version of your compiler." ) ,
1591- new Choice ( ) { new PrimitiveExpression ( true ) , new PrimitiveExpression ( false ) }
1592- }
1593- } ;
1594-
15951578 EntityDeclaration DoDecompile ( IMethod method , DecompileRun decompileRun , ITypeResolveContext decompilationContext )
15961579 {
15971580 Debug . Assert ( decompilationContext . CurrentMember == method ) ;
@@ -1645,6 +1628,10 @@ EntityDeclaration DoDecompile(IMethod method, DecompileRun decompileRun, ITypeRe
16451628 methodDecl . Modifiers &= ~ ( Modifiers . New | Modifiers . Virtual ) ;
16461629 methodDecl . Modifiers |= Modifiers . Override ;
16471630 }
1631+ if ( method . IsConstructor && settings . RequiredMembers && RemoveCompilerFeatureRequiredAttribute ( methodDecl , "RequiredMembers" ) )
1632+ {
1633+ RemoveObsoleteAttribute ( methodDecl , "Constructors of types with required members are not supported in this version of your compiler." ) ;
1634+ }
16481635 return methodDecl ;
16491636
16501637 bool IsTypeHierarchyKnown ( IType type )
@@ -1877,6 +1864,30 @@ internal static bool RemoveCompilerFeatureRequiredAttribute(EntityDeclaration en
18771864 return found ;
18781865 }
18791866
1867+ internal static bool RemoveObsoleteAttribute ( EntityDeclaration entityDecl , string message )
1868+ {
1869+ bool found = false ;
1870+ foreach ( var section in entityDecl . Attributes )
1871+ {
1872+ foreach ( var attr in section . Attributes )
1873+ {
1874+ var symbol = attr . Type . GetSymbol ( ) ;
1875+ if ( symbol is ITypeDefinition td && td . FullTypeName == KnownAttribute . Obsolete . GetTypeName ( )
1876+ && attr . Arguments . Count >= 1 && attr . Arguments . First ( ) is PrimitiveExpression pe
1877+ && pe . Value is string s && s == message )
1878+ {
1879+ attr . Remove ( ) ;
1880+ found = true ;
1881+ }
1882+ }
1883+ if ( section . Attributes . Count == 0 )
1884+ {
1885+ section . Remove ( ) ;
1886+ }
1887+ }
1888+ return found ;
1889+ }
1890+
18801891 bool FindAttribute ( EntityDeclaration entityDecl , KnownAttribute attributeType , out Syntax . Attribute attribute )
18811892 {
18821893 attribute = null ;
0 commit comments