Find object creations of classes without constructors

Hi,

I have a class that doesn't contain a constructor, i.e.

class ClassA
{
     public int Prop1 { get; set; }
}

How can I find all places in my code where this class ClassA is instantiated ?

I know the workaround to:
shortly add the default constructor to that class -> select default constructor -> Select "Find Usages"

Is there a shorter way ?

3 comments
Comment actions Permalink

Hello,

How can I find all places in my code where this class ClassA is
instantiated ?


Find usages of the class itself. As you have the usages in the Find Results
tool window, you can filter them by the usage type -- invocation usage, in
this case.


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0
Comment actions Permalink

This does not work with ReSharper 4.5.2. You can try it with following code:

namespace ShortTests
{
  internal class Program
  {
    private static void Main(string[] args)
    {
      ClassA classA = new ClassA();
      classA.Prop1 = 1;
    }
  }

  internal class ClassA
  {
    public int Prop1 { get; set; }
  }
}


ClassA does not have a constructor.
If I use "Find usages" of the class itself the window "Find Results" shows all usages. The filter "invocation usage" is grayed out. See attachment.



Attachment(s):
FindCreations.JPG
0
Comment actions Permalink

Hello,

You're right -- this feature appears to be broken :(

We'll try to have it fixed by 5.0 release.


Serge Baltic
JetBrains, Inc — http://www.jetbrains.com
“Develop with pleasure!”


0

Please sign in to leave a comment.