@@ -3866,18 +3866,47 @@ bool DoesPropertyNeedDirtyCheck (PropertyInfo pi, ExportAttribute ea)
3866
3866
}
3867
3867
}
3868
3868
3869
- void PrintObsoleteAttributes ( ICustomAttributeProvider provider , bool already_has_editor_browsable_attribute = false )
3869
+ void PrintObsoleteAttributes ( ICustomAttributeProvider provider )
3870
3870
{
3871
3871
var obsoleteAttributes = AttributeManager . GetCustomAttributes < ObsoleteAttribute > ( provider ) ;
3872
3872
3873
3873
foreach ( var oa in obsoleteAttributes ) {
3874
3874
print ( "[Obsolete (\" {0}\" , {1})]" , oa . Message , oa . IsError ? "true" : "false" ) ;
3875
3875
}
3876
3876
3877
- if ( ! already_has_editor_browsable_attribute && obsoleteAttributes . Any ( ) )
3877
+ var printEditorBrowsableAttribute = TryGetPrintEditorBrowsableAttribute ( provider , out var editorBrowsableAttribute ) ;
3878
+ if ( ! printEditorBrowsableAttribute && obsoleteAttributes . Any ( ) ) {
3879
+ printEditorBrowsableAttribute = true ;
3880
+ editorBrowsableAttribute = "[EditorBrowsable (EditorBrowsableState.Never)]" ;
3881
+ }
3882
+ if ( printEditorBrowsableAttribute )
3878
3883
print ( "[EditorBrowsable (EditorBrowsableState.Never)]" ) ;
3879
3884
}
3880
3885
3886
+ bool TryGetPrintEditorBrowsableAttribute ( ICustomAttributeProvider provider , out string attribute )
3887
+ {
3888
+ attribute = string . Empty ;
3889
+ foreach ( var ea in AttributeManager . GetCustomAttributes < EditorBrowsableAttribute > ( provider ) ) {
3890
+ switch ( ea . State ) {
3891
+ case EditorBrowsableState . Always :
3892
+ attribute = "[EditorBrowsable (EditorBrowsableState.Always)]" ;
3893
+ break ;
3894
+ case EditorBrowsableState . Never :
3895
+ attribute = "[EditorBrowsable (EditorBrowsableState.Never)]" ;
3896
+ break ;
3897
+ case EditorBrowsableState . Advanced :
3898
+ attribute = "[EditorBrowsable (EditorBrowsableState.Advanced)]" ;
3899
+ break ;
3900
+ default :
3901
+ attribute = $ "[EditorBrowsable (EditorBrowsableState.{ ea . State } )]";
3902
+ break ;
3903
+ }
3904
+ return true ;
3905
+ }
3906
+
3907
+ return false ;
3908
+ }
3909
+
3881
3910
void PrintPropertyAttributes ( PropertyInfo pi , Type type , bool skipTypeInjection = false )
3882
3911
{
3883
3912
var minfo = new MemberInformation ( this , this , pi , type ) ;
@@ -4418,21 +4447,11 @@ void GenerateAsyncMethod (MemberInformation original_minfo, AsyncMethodKind asyn
4418
4447
void PrintMethodAttributes ( MemberInformation minfo )
4419
4448
{
4420
4449
MethodInfo mi = minfo. Method ;
4421
- var editor_browsable_attribute = false ;
4422
4450
4423
4451
foreach ( var sa in AttributeManager . GetCustomAttributes < ThreadSafeAttribute > ( mi ) )
4424
4452
print ( sa . Safe ? "[ThreadSafe]" : "[ThreadSafe (false)]" ) ;
4425
4453
4426
- foreach ( var ea in AttributeManager . GetCustomAttributes < EditorBrowsableAttribute > ( mi ) ) {
4427
- if ( ea . State == EditorBrowsableState . Always ) {
4428
- print ( "[EditorBrowsable]" ) ;
4429
- } else {
4430
- print ( "[EditorBrowsable (EditorBrowsableState.{0})]" , ea . State ) ;
4431
- }
4432
- editor_browsable_attribute = true;
4433
- }
4434
-
4435
- PrintObsoleteAttributes ( mi , editor_browsable_attribute ) ;
4454
+ PrintObsoleteAttributes ( mi ) ;
4436
4455
4437
4456
if ( minfo . is_return_release )
4438
4457
print ( "[return: ReleaseAttribute ()]" ) ;
@@ -5507,7 +5526,7 @@ public void PrintBindAsAttribute (ICustomAttributeProvider mi, StringBuilder sb
5507
5526
// Not adding the experimental attribute is bad (it would mean that an API
5508
5527
// we meant to be experimental ended up being released as stable), so it's
5509
5528
// opt-out instead of opt-in.
5510
- public void PrintAttributes ( ICustomAttributeProvider mi , bool platform = false , bool preserve = false , bool advice = false , bool notImplemented = false , bool bindAs = false , bool requiresSuper = false , Type inlinedType = null , bool experimental = true )
5529
+ public void PrintAttributes ( ICustomAttributeProvider mi , bool platform = false , bool preserve = false , bool advice = false , bool notImplemented = false , bool bindAs = false , bool requiresSuper = false , Type inlinedType = null , bool experimental = true , bool obsolete = false )
5511
5530
{
5512
5531
if ( platform )
5513
5532
PrintPlatformAttributes ( mi as MemberInfo , inlinedType ) ;
@@ -5523,6 +5542,8 @@ public void PrintAttributes (ICustomAttributeProvider mi, bool platform = false,
5523
5542
PrintRequiresSuperAttribute ( mi ) ;
5524
5543
if ( experimental )
5525
5544
PrintExperimentalAttribute ( mi ) ;
5545
+ if ( obsolete )
5546
+ PrintObsoleteAttributes ( mi ) ;
5526
5547
}
5527
5548
5528
5549
public void PrintExperimentalAttribute ( ICustomAttributeProvider mi )
@@ -5754,7 +5775,7 @@ public void Generate (Type type)
5754
5775
print ( "[Model]" ) ;
5755
5776
}
5756
5777
5757
- PrintAttributes ( type , platform : true , preserve : true , advice : true ) ;
5778
+ PrintAttributes ( type , platform : true , preserve : true , advice : true , obsolete : true ) ;
5758
5779
5759
5780
if ( type . IsEnum ) {
5760
5781
GenerateEnum ( type ) ;
0 commit comments