@@ -1397,16 +1397,7 @@ EntityDeclaration DoDecompile(ITypeDefinition typeDef, DecompileRun decompileRun
1397
1397
}
1398
1398
if ( settings . IntroduceRefModifiersOnStructs )
1399
1399
{
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." ) ;
1410
1401
RemoveCompilerFeatureRequiredAttribute ( typeDecl , "RefStructs" ) ;
1411
1402
}
1412
1403
if ( settings . RequiredMembers )
@@ -1584,14 +1575,6 @@ EnumValueDisplayMode DetectBestEnumValueDisplayMode(ITypeDefinition typeDef, PEF
1584
1575
return firstValue == 0 ? EnumValueDisplayMode . None : EnumValueDisplayMode . FirstOnly ;
1585
1576
}
1586
1577
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
-
1595
1578
EntityDeclaration DoDecompile ( IMethod method , DecompileRun decompileRun , ITypeResolveContext decompilationContext )
1596
1579
{
1597
1580
Debug . Assert ( decompilationContext . CurrentMember == method ) ;
@@ -1645,6 +1628,10 @@ EntityDeclaration DoDecompile(IMethod method, DecompileRun decompileRun, ITypeRe
1645
1628
methodDecl . Modifiers &= ~ ( Modifiers . New | Modifiers . Virtual ) ;
1646
1629
methodDecl . Modifiers |= Modifiers . Override ;
1647
1630
}
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
+ }
1648
1635
return methodDecl ;
1649
1636
1650
1637
bool IsTypeHierarchyKnown ( IType type )
@@ -1877,6 +1864,30 @@ internal static bool RemoveCompilerFeatureRequiredAttribute(EntityDeclaration en
1877
1864
return found ;
1878
1865
}
1879
1866
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
+
1880
1891
bool FindAttribute ( EntityDeclaration entityDecl , KnownAttribute attributeType , out Syntax . Attribute attribute )
1881
1892
{
1882
1893
attribute = null ;
0 commit comments