Find usage of property from base entity

北慕城南 提交于 2019-12-19 03:46:11

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/26775848/find-usage-of-property-from-base-entity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!