Skip to content

Commit 18bf907

Browse files
committed
Disable warning CS0618 when using Obsolete with a message
1 parent 190229b commit 18bf907

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

src/Abc.Zebus.MessageDsl.Tests/MessageDsl/CSharpGeneratorTests.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ public async Task should_handle_obsolete_attribute_1()
352352
}
353353
});
354354

355-
code.ShouldNotContain("#pragma warning disable 612");
355+
code.ShouldNotContain("#pragma warning disable CS0612, CS0618");
356356
}
357357

358358
[Test]
@@ -370,7 +370,7 @@ public async Task should_handle_obsolete_attribute_2()
370370
}
371371
});
372372

373-
code.ShouldContain("#pragma warning disable 612");
373+
code.ShouldContain("#pragma warning disable CS0612, CS0618");
374374
}
375375

376376
[Test]
@@ -382,7 +382,19 @@ public async Task should_handle_obsolete_attribute_3()
382382
Attributes = { new AttributeDefinition("Obsolete") }
383383
});
384384

385-
code.ShouldContain("#pragma warning disable 612");
385+
code.ShouldContain("#pragma warning disable CS0612, CS0618");
386+
}
387+
388+
[Test]
389+
public async Task should_handle_obsolete_attribute_4()
390+
{
391+
var code = await Verify(new MessageDefinition
392+
{
393+
Name = "FooExecuted",
394+
Attributes = { new AttributeDefinition("Obsolete", "\"Custom message\"") }
395+
});
396+
397+
code.ShouldContain("#pragma warning disable CS0612, CS0618");
386398
}
387399

388400
[Test]

src/Abc.Zebus.MessageDsl.Tests/MessageDsl/ParsedContractsTests.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@ public void should_handle_attributes()
138138
msg.Parameters[0].Attributes[0].TypeName.ShouldEqual(new TypeName("Lol"));
139139
}
140140

141+
[Test]
142+
public void should_handle_attributes_2()
143+
{
144+
var contracts = ParseValid("""[Transient(), Obsolete] FooExecuted(int id);""");
145+
146+
var msg = contracts.Messages.ExpectedSingle();
147+
msg.Attributes.Count.ShouldEqual(2);
148+
msg.Attributes[0].TypeName.ShouldEqual(new TypeName("Transient"));
149+
msg.Attributes[0].Parameters.ShouldNotBeNull().ShouldBeEmpty();
150+
msg.Attributes[1].TypeName.ShouldEqual(new TypeName("Obsolete"));
151+
msg.Attributes[1].Parameters.ShouldBeNull();
152+
}
153+
141154
[Test]
142155
public void should_set_message_as_transient()
143156
{
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//------------------------------------------------------------------------------
2+
// <auto-generated>
3+
// This code was generated by a tool.
4+
// </auto-generated>
5+
//------------------------------------------------------------------------------
6+
7+
using System;
8+
using Abc.Zebus;
9+
using ProtoBuf;
10+
11+
#pragma warning disable CS0612, CS0618
12+
13+
[ProtoContract]
14+
[System.Diagnostics.DebuggerNonUserCode]
15+
[System.CodeDom.Compiler.GeneratedCode("Abc.Zebus.MessageDsl", "1.2.3.4")]
16+
[Obsolete("Custom message")]
17+
public sealed partial class FooExecuted : IEvent
18+
{
19+
}

src/Abc.Zebus.MessageDsl/Generator/CSharpGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ private void WritePragmas()
108108

109109
if (hasObsolete)
110110
{
111-
Writer.WriteLine("#pragma warning disable 612");
111+
Writer.WriteLine("#pragma warning disable CS0612, CS0618");
112112
Writer.WriteLine("");
113113
}
114114
}

0 commit comments

Comments
 (0)