Вопрос

Code

I would like to use the ReSharper Move Types Into Matching Files functionality to move the code below which is written in a single .cs'. file:

public abstract class Foo
{

}

public abstract class Foo<T> : Foo
{

}

Executing the ReSharper refactoring causes this exception:

Can not move class Foo because there is another declaration that will be moved into file 'Foo.cs'.

Question

I can think of two outcomes of which either are ok by me:

  1. Move both Foo and Too<T> into Foo.cs
  2. Move Foo into Foo.cs and move Foo<T> into FooOfT.cs

So, the question remains:

  1. Is there another best naming practise that does not conflict with resharper?, or
  2. Is there a way to configure ReSharper to support this naming?

Note

  • Because Generics are unique for each possible combination of constraints, the Foo class is my interface class. Therefore I won't rename Foo<T> to Bar<T>.
  • I do not wish to rename Foo to FooBase as it is already an abstract class which makes the explicit 'Base' suffix redundant.
  • I cannot refactor Foo to IFoo as Foo is my conceptual interface (because of a required basic implementation.
Это было полезно?

Решение

As far as I know, there is no way to tell Resharper to append the generic parameters of the filename. It will just use the class name, i.e. Foo, Foo<T> and Foo<A, B, C> all have Foo.cs as the filename, but - and that's the problem - ReSharper doesn't seem to know that this possibility exists and will show you an error in this scenario. Really nothing you can do about it except logging a bug or feature request.

Другие советы

You may consider these options:

  • Use AbstractFoo
  • Change Foo to an interface, if possible, and use IFoo
  • Use GenericFoo
  • Use different namespaces for Foo and Foo<T> and put them in different folders.
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top