There is an attribute ObsoleteAttribute
that can be used to indicate that a type or member will be removed in a future update and should not be used. I’m working with a large codebase that utilizes some outdated patterns and conventions and I want to hint that its use should be discouraged for future code, at least until we can get a chance to clean things up for the entire codebase (which is unlikely).
e.g.,
public class SomeWidelyUsedClass
{
// examples of the old approach
public int? SomeInt { get; set; }
public int? SomeIntId { get; set; }
public string SomeIntDisplayName { get; set; }
public int? AnotherInt { get; set; }
public int? AnotherIntId { get; set; }
public string AnotherIntDisplayName { get; set; }
public DateTime? SomeDate { get; set; }
public int? SomeDateId { get; set; }
public string SomeDate1DisplayName { get; set; }
// the newer approach, utilizing objects to contain related data
public FieldInfo<int?> NewSomeInt { get; set; }
public FieldInfo<DateTime?> NewSomeDate { get; set; }
}
I will try to follow the pattern of the established code, despite my own personal tastes when making changes except for really egregious patterns. Then try to follow that pattern for new code where appropriate. But we want to go with the new approach so I want to let others know that this is the direction we should go.
Does there exist an attribute that indicates that a type or member’s use should be discouraged in favor of another approach? Something like a “DiscouragedAttribute” or a “DoNotUseThisPatternAttribute.” How do we document that entire patterns should be phased out for something else?
Using ObsoleteAttribute
in this case doesn’t feel right to me as it targets specific members, and indicates it will be removed in the near future. I want to discourage an entire pattern. I also considered using XXX
comments to explain why these should not be used but I don’t think it is effective for spreading the word as it’s not highlighted by the IDE as something that should be considered. Same for XML docs.
For now, I’m applying ObsoleteAttribute
to extension methods that have been added to try to simplify accessing/mapping to these members to discourage it but I’d hope there’s a better approach. But there are already at least 5 different variations of these methods already and I don’t want it to get out of hand.
// I added this previously to replace some really ugly mapping code
[Obsolete("Consider using FieldInfo<T> type for newly mapped fields")]
public static int? GetIntValue(this IDataRepository data, string name, out int? id, out string displayName);