forked from protobuf-net/protobuf-net
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
protobuf-net#1149 Support deprecated options
- Updated `MetaType` to check if `System.ObsoleteAttribute` exists on type or field to add deprecated option while generating proto. - Added unit test to reproduce the issue.
- Loading branch information
1 parent
93b8be6
commit bfee7a4
Showing
2 changed files
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
using System; | ||
using ProtoBuf.Meta; | ||
using Xunit; | ||
|
||
namespace ProtoBuf.Test.Issues | ||
{ | ||
#pragma warning disable CS0612 // Type or member is obsolete | ||
public sealed class Issue1149 | ||
{ | ||
[Fact] | ||
public void GenerateProtoWithDeprecatedOption() | ||
{ | ||
const string expected = @"syntax = ""proto3""; | ||
package DefaultPackage; | ||
message SomeClass { | ||
option deprecated = true; | ||
int32 SomeProperty = 1; | ||
} | ||
enum SomeEnum { | ||
option deprecated = true; | ||
One = 0; | ||
Two = 1; | ||
Three = 2; | ||
} | ||
message SomeOtherClass { | ||
string SomeOtherProperty = 1 [deprecated = true]; | ||
} | ||
"; | ||
|
||
var actual = Serializer.GetProto(new SchemaGenerationOptions | ||
{ | ||
Syntax = ProtoSyntax.Proto3, | ||
Package = "DefaultPackage", | ||
Types = { typeof(SomeClass), typeof(SomeOtherClass), typeof(SomeEnum) }, | ||
}); | ||
|
||
Assert.Equal(expected, actual); | ||
} | ||
|
||
[ProtoContract] | ||
[Obsolete] | ||
public class SomeClass | ||
{ | ||
[ProtoMember(tag: 1)] | ||
public int SomeProperty { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
public class SomeOtherClass | ||
{ | ||
[ProtoMember(tag: 1)] | ||
[Obsolete] | ||
public string SomeOtherProperty { get; set; } | ||
} | ||
|
||
[ProtoContract] | ||
[Obsolete] | ||
public enum SomeEnum | ||
{ | ||
One, | ||
Two, | ||
Three, | ||
} | ||
} | ||
#pragma warning restore CS0612 // Type or member is obsolete | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters