Git Product home page Git Product logo

obsolete's Introduction

This is an add-in for Fody

Icon

Helps keep usages of ObsoleteAttribute consistent.

Introduction to Fody

The nuget package NuGet Status

https://nuget.org/packages/Obsolete.Fody/

PM> Install-Package Obsolete.Fody

Your Code

[ObsoleteEx(
            Message = "Custom message.", 
            TreatAsErrorFromVersion = "2.0", 
            RemoveInVersion = "4.0", 
            ReplacementTypeOrMember = "NewClass")]
public class ClassToMark {}

Treat As Warning Mode

When the target assembly version is less than RemoveInVersion an ObsoleteAttribute with "treat as warning" will be injected. It will have the following format

[Obsolete("MESSAGE. Use 'REPLACED_WITH' instead. Will be treated as an error from version MARK_AS_VERSION_IN. Will be removed in version WILL_BE_REMOVED_IN_VERSION.")]

So given the above example when the assembly version is 1.0 the following will be injected

[Obsolete("Custom Message. Use 'NewClass' instead. Will be treated as an error from version 2.0.0. Will be removed in version 4.0.0.")]
public class ClassToMark{}

Treat As Error Mode

When the target assembly version is greater than RemoveInVersion but less than TreatAsErrorFromVersion an ObsoleteAttribute with "treat as error" will be injected. It will have the following format

[Obsolete("MESSAGE. Use 'REPLACED_WITH' instead. Will be removed in version WILL_BE_REMOVED_IN_VERSION.", true)]

So given the above example when the assembly version is 3.0 the following will be injected

[Obsolete("Custom Message. Use 'NewClass' instead. Will be removed in version 4.0.0.", true)]
[EditorBrowsable(EditorBrowsableState.Advanced)]
public class ClassToMark{}

Build Error Mode

When the target assembly version is greater than TreatAsErrorFromVersion a build error will be generated. It will have the following format

 Cannot process 'MEMBER_NAME'. The assembly version ASSEMBLY_VERSION is higher than version specified in 'RemoveInVersion' WILL_BE_REMOVED_IN_VERSION. The member should be removed or 'RemoveInVersion' increased.

So given the above example when the assembly version is 5.0 a compile error will be thrown with the following text

 Cannot process 'ClassToMark'. The assembly version 5.0.0 is higher than version specified in RemoveInVersion 4.0.0. The member should be removed or RemoveInVersion increased.

The Message property

The message property should only be used for useful information. The fact that it is obsoleted does not need to be reiterated in the message.

DO NOT use and of the following redundant messages

  • "Do not call this method"
  • "This method will be removed"
  • "This method is obsolete"
  • "The replacement method is"

Configuration Options

All configuration options are access by modifying the Obsolete node in FodyWeavers.xml

HideObsoleteMembers

When this is true obsolete members will also have [EditorBrowsable(EditorBrowsableState.Advanced)] added to them.

Defaults to true

<Obsolete HideObsoleteMembers='false'/>

TreatAsErrorFormat

The string used when informing the user what version the member will be treated as an error.

Defaults to Will be treated as an error from version {0}.

<Obsolete TreatAsErrorFormat="Will be treated as an error from version {0}. "/>

ThrowsNotImplementedText

The string used when informing the user when the member currently throws a NotImplementedException.

Defaults to The member currently throws a NotImplementedException.

<Obsolete ThrowsNotImplementedText="The member currently throws a NotImplementedException. "/>

RemoveInVersionFormat

The string used when informing the user what version the member will be removed it.

Defaults to Will be removed in version {0}.

<Obsolete RemoveInVersionFormat="Will be removed in version {0}. "/>

ReplacementFormat

The string used when informing the user of an alternative member to use instead of the obsolete member.

Defaults to Use {0} instead.

<Obsolete ReplacementFormat="Use {0} instead. "/>

StepType

Used in two cases

  • To derive TreatAsErrorFromVersion if RemoveInVersion is not defined.
  • To derive RemoveInVersion if TreatAsErrorFromVersion is not defined.

Defaults to Major. Other options are Minor and Patch

<Obsolete StepType="Minor"/>

Icon

Icon courtesy of The Noun Project

obsolete's People

Contributors

andreasohlund avatar simoncropp avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.