4

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.
Myrtle
  • 5,761
  • 33
  • 47
  • 1
    I've sometimes named generic files Foo`1.cs to denote one generic type argument on Foo. But this isn't using ReSharper. – Adam Houldsworth Sep 06 '13 at 14:46
  • 1
    "At Microsoft, they use `ClassNameOfT.cs`." http://stackoverflow.com/a/804114/781792 – Tim S. Sep 06 '13 at 14:48
  • @TimS. That is exactly my second suggestion. However, It seems that unfortunately ReSharper does not support this naming convention. – Myrtle Sep 06 '13 at 14:49
  • 1
    @MauriceStam That'll work until you have something like your own `Tuple` with multiple type arguments, but in different files lol – Adam Houldsworth Sep 06 '13 at 14:53
  • Create a folder for one or the other or two folders, one for each. Then they can have the same file name. – Jesse C. Slicer Sep 06 '13 at 15:55
  • 1
    @JesseC.Slicer Thank you for the suggestion. Unfortunately that is no solution because I would like the folder structure to follow the namespace structure. – Myrtle Sep 06 '13 at 17:09

2 Answers2

1

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.

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
1

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.
Ahmed KRAIEM
  • 10,267
  • 4
  • 30
  • 33
  • Unfortunately `Foo` is already my 'conceptual' interface class. However I require some basic implementation therefore I use an abstract class instead of an c# interface. – Myrtle Sep 06 '13 at 14:49
  • You could also develop a Resharper plugin that does what you want. – Ahmed KRAIEM Sep 06 '13 at 14:51