Suppose that I have this file:
// Copyright © 2016 …
// blabla
namespace Foo
{
public struct Any
{
public Any (int x) { this.x = x; }
private readonly int x;
}
}
When using the Implement IEquatable refactoring, I see two issues:
- The `using System;` is added at the very beginning of my source, even before my // copyright comments
- I don't like to have `using System;` in my source code, so every time I use an auto-implementation of an interface, I get this added (either because some NotImplementedException are thrown, without fully qualifying the exception with `System.` namespace, or here because the interface is referenced directly as struct Any : IEquatable<Any>).
(1) appears to be an error.
(2) should be customizable.
And by the way, I don't like the way IEquatable is implemented.
I don't see how you could provide enough flexibility to please all possible coding styles ;-)
Hi Pierre,
Thanks for pointing out the problems to us.
I have created two separate tickets to discuss your suggestions:
>1) The `using System;` is added at the very beginning of my source, even before my // copyright comments
The "Implement IEquatable" feature - A namespace reference is incorrectly added before the first comment after the feature is applied
>3) fields referenced without `this`.
The "Implement IEquatable" feature should process the "Use 'this/qualifier for:'" option for fields correctly
CodeRush for Roslyn has options CodeRush->Options->Editor->Code Style->Programming Style -> "Use 'this/qualifier for:'",
but the option incorrectly works in the current case.
Also, we already have plans to implement the following functionality and we will try to do so in the nearest releases:
>1) if statements without code blocks { }
>2) calls to ReferenceEquals() without explicitely writing object.ReferenceEquals()
Could you clarify one point:
>) I don't like to have `using System;` in my source code, so every time I use an auto-implementation of an interface
Do you suggest generating code with fully qualified names ( struct Any : System.IEquatable<Any>) and without namespace references (using System, using …)?
I am looking forward to your response.
Hi Dmitry, thanks a lot for your time.
Let me first repeat that I really appreciate the way DevExpress takes care of its customers!
To your question, let me clarify.
Generally speaking, I don't like the idea of having `using Namespace;` being added automatically for me when I ask a tool to auto-implement something. I'd rather have it use the fully qualified type names, unless the namespace is already referenced to by a `using`.
And in our code base, we do not include `System` as it has some types which interfere with our own types.
Here is the reasoning:
Say we have some Foo.EventArgs in our code base, and we do a `using Foo;` at the beginning of the source file.
Adding automatically a `using System;` will then call for trouble. System.EventArgs will be conflicting with our own Foo.EventArgs.
Thank you for the clarification.
I agree that CodeRush for Roslyn should have an option for generating fully qualified type names instead of adding namespase references. But, as far as I understand, you suggest generating fully qualified type names because of possible conflicts in code of a current file. In my opinion, the best variant for your code snippets is to have an option that will add namespace references if generated namespace reference do not cause conflicts in the current file, but, for conflicts, fully qualified type names should be generated…
Would such a code generation option be useful for you?
No, I'd prefer that the code generation never adds namespace references. Or else I'll have to remove them by hand later on. I'd rather have an option which lets me configure how types get referenced.
Pierre,
Thank you for the clarification. I agree with you that such an option might be useful in refactorings. I will discuss this with our team and we will possibly consider implementing it in future versions of the product.
We have added a new Code Style rule for the declaration of the new Namespace reference imports/using statement. Please read our What's New in v16.2.7 for more details.
Now the declaration of using/imports statements is tied up with the sorting rules specified on Editor/All Languages/Namespace References options page.
Thank you, this closes the issue.
Hi Pierre,
Thank you for informing us that you found this solution useful.
We're here to help you.