-
Notifications
You must be signed in to change notification settings - Fork 62
Description
When we are converting Java getter/setter pairs to C# properties, we can hit an interesting scenario where a getter may be @Deprecated and the setter is not, or vice versa:
public boolean hasOptionsMenu () { ... }
@Deprecated
public void setHasOptionsMenu (boolean hasMenu) { ... }C# has traditionally not allowed [Obsolete] to be placed on just a get or a set, it can only be placed on the entire property.
[Obsolete]
public bool HasOptionsMenu { get; set; }This can lead to confusion because using the getter will report an obsolete warning when it is not obsolete. Thus, for properties, we only add [Obsolete] in 2 cases:
- The
getis obsolete and there is noset - Both the
getandsetare obsolete
We have this comment in our code:
// Unlike [Register], [Obsolete] cannot be put on property accessors, so we can apply them only under limited condition...
However, the compiler team has determined that preventing [Obsolete] on property accessors was a bug, and has fixed it in C# 8: dotnet/roslyn#32571.
Thus we can update generator to support scenarios in which only the Java getter or setter is marked as @Deprecated.