DotNetAnalyzers / NullParameterCheckRefactoring

Null Parameter Check Refactoring for Reference Type Parameters
MIT License
14 stars 4 forks source link

Handle System using statements correctly #5

Closed tugberkugurlu closed 10 years ago

tugberkugurlu commented 10 years ago

When there is no System using statement or the class/struct is not under a System or System.* namespace, the current implementation is buggy:

screenshot 2014-11-18 13 19 00

image

Questions:

sharwell commented 10 years ago

You need to use the fully-qualified name, and then add Simplifier.Annotation.

tugberkugurlu commented 10 years ago

Doesn't work :disappointed:

screenshot 2014-11-18 13 50 17 screenshot 2014-11-18 13 50 21

Am I doing something wrong: https://github.com/DotNetAnalyzers/NullParameterCheckRefactoring/commit/91868474bd7512f395f6962851ccb7605505dad7?

sharwell commented 10 years ago

It looks like it's working to me, assuming it inserts just ArgumentNullException when the file does contain a using System; declaration.

tugberkugurlu commented 10 years ago

Weird, I cannot get it working in my box. It always adds it as System.ArgumentNullException if I don't have a using statement for System. Is this the right place to add Simplifier.Annotation: https://github.com/DotNetAnalyzers/NullParameterCheckRefactoring/commit/91868474bd7512f395f6962851ccb7605505dad7#diff-cdeec3cc19b47b81331208ac85ae1c83R107?

sharwell commented 10 years ago

The important part is that it always inserts a valid reference to System.ArgumentNullException. You also want it to use the shortest form available during the code fix. For now you probably won't get it to automatically insert the using System; statement, but this is arguably a bad idea anyway (perhaps the user omitted it on purpose).