304NotModified / ObsoleteFixer

:wrench: Roslyn Fixer for ObsoleteAttribute in C# :sparkles:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Obsolete Fixer โœจ

Visual Studio Marketplace Version

Fixer for [Obsolete] in C# with the powers of Roslyn! ๐Ÿ’Ž

Currently supported:

  • Method calls
  • Getters
  • Setters
  • contructor calls: new MyClass - no transformation of parameters yet
  • static method, getters or setter calls and change type.

Arguments values could also be transformed, see examples.

image

Message syntax

To unleash the powers of this fixer, the text in the [Obsolete] needs to be in a recognisable format.

The replace value needs to between backticks (`) and after the text Replace with (case insensitive). Text before and after the "Replace with" is OK.

Examples OK:

  • ๐Ÿ‘ [Obsolete("Replace with `MyNewMethod`")]
  • ๐Ÿ‘ [Obsolete("Replace with `MyNewMethod(x, y)`")]
  • ๐Ÿ‘ [Obsolete("Replace with: `MyNewMethod`")]
  • ๐Ÿ‘ [Obsolete("This method will be replaced! Replace with: `MyNewMethod`. This will be removed in version 123")]

Examples nope:

  • ๐Ÿ‘Ž [Obsolete("Replace with 'MyNewMethod'")] - no backticks

Examples

Simple method replacement

Given:

class MyClass
{

    [Obsolete("Replace with `MyNewMethod`")]
    public void MyOldMethod(string x, object y)
    {

    }

    public void MyNewMethod(string x2, object y2)
    {

    }
}

and call

myClass.MyOldMethod("text", 2);

Will be after the fix:

myClass.MyNewMethod("text", 2);

Method replacement with argument transformations

Given:

class MyClass
{

    [Obsolete("Replace with `MyNewMethod(y, x, \"text2\")`")]
    public void MyOldMethod(string x, object y)
    {

    }

    public void MyNewMethod(object y, string x, string y2)
    {

    }
}

Note the argument's order has been changed and a new argument has been added! ๐Ÿ˜€

When having this call:

myClass.MyOldMethod("text", 2);

Will be after the fix:

myClass.MyNewMethod(2, "text", "text2");

FAQ

Why do I need this?

Because fixing obsolete code is boring! ๐Ÿ˜ด ๐Ÿ˜ด

Why is the syntax so strict?

I prefer that the code could still be compiled after the fix. ๐Ÿ˜Ž

Will the syntax be configurable?

Not sure, also not sure how that works with the VISX

Why all those emojis ๐Ÿ˜ฎ ?

๐Ÿ˜† ๐Ÿ™ˆ

Roadmap

  • Inheritance: Support for changing base class / interface
  • Constructor with parameter transformation
  • Transformation of parameter type? (e.g. int to string)
  • Namespace support (e.g. only change the namespace)

About

:wrench: Roslyn Fixer for ObsoleteAttribute in C# :sparkles:

License:MIT License


Languages

Language:C# 95.7%Language:PowerShell 4.3%