4

I'm trying to find the usage of a property in a class where the property belongs to a base class. Here is a token example:

class Program
{
    class Item
    {
        public DateTime DeletedStamp { get; set; }

        public decimal Price { get; set; }
    }

    class Book : Item
    {
        public string Title { get; set; }

        public string Author { get; set; }
    }

    class Bicycle : Item
    {
        public string Type { get; set; }

        public string Producer { get; set; }
    }

    static void Main(string[] args)
    {
        var book = new Book()
        {
            Title = "Atlas Shrugged",
            Author = "Ayn Rand",
            Price = 2.99M
        };

        var bicycle = new Bicycle()
        {
            Type = "Mountain bike",
            Price = 499.99M,
            Producer = "Biker Ben",
            DeletedStamp = DateTime.Now
        };

        Console.WriteLine(book.Title);
        Console.WriteLine(book.Price);

        Console.WriteLine(bicycle.Price);
        Console.WriteLine(bicycle.DeletedStamp);
    }
}

If I want to find the usage of Price in only bicycle items I find that I'm out of luck. I'm using re-sharper in Visual Studio 2013 and Find Usage finds all usage of Price including the usage in Book. This is a small example but with a base class used in a lot of other classes it becomes impossible to track down usages.

I'm looking for any tip, trick, extension or magic spell to solve this dilemma.

Maffelu
  • 2,018
  • 4
  • 24
  • 35

1 Answers1

6

For this case is very usefull the ReSharper's SRP (Search and Replace with Pattern).

Menu Resharper->Find->Search with Pattern...

define here following pattern:

$Item$.Price

of for write usages only:

$Item$.Price = $exp$;

or for read usages only:

$exp$ = $Item$.Price

where $Item$ should be an expression placeholder, select the type "Bicycle" and don't forget to check "Exactly this type".

The $exp$ can stay undefined

python_kaa
  • 1,034
  • 13
  • 27
  • This was excellent! I have looked for a way to do this for a long time and I have been told it wasn't possible. SO disagrees :) – Maffelu Nov 10 '14 at 07:07