I need to force the use of \"using\" to dispose a new instance of a class.
public class MyClass : IDisposable
{
...
}
using(MyClass obj = new MyClass())
You can write your own warning/error with the use of the Roslyn framework. Your DiagnosticAnalyzer would check all constructor calls to see if your class is being constructed or not and if you are within a using statement or not.
The reported diagnostic can be set to Error severity, and can be marked as non-configurable, meaning that nobody can downgrade it to warning or info.
Also, if you are developing a Nuget library you might want to ship your analyzer as a development dependency and add it as an analyzer nuget package. This would result in all of your users being forced to dispose your given class. This packaging is referred to as "code-aware library".
Note that in theory this could be done by a third party analyzer library too (such as FxCop), but there are many IDisposable implementations that do not strictly need to be disposed, such as MemoryStream, whose Dispose doesn't do a whole lot, so these rules either have some white-listing mechanisms or report false positives.