Maf*_*elu 4 c# resharper visual-studio-2013
我试图在属性属于基类的类中找到属性的用法.这是一个标记示例:
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);
    }
}
如果我想在自行车项目中找到Price的用法,我发现我运气不好.我在Visual Studio 2013中使用re-sharper,而Find Usage查找了Price的所有用法,包括Book中的用法.这是一个小例子,但是在很多其他类中使用了基类,因此无法追踪使用情况.
我正在寻找任何提示,技巧,扩展或魔法来解决这个难题.
对于这种情况,ReSharper的SRP(用模式搜索和替换)非常有用.
Menu Resharper->查找 - >用模式搜索...
在这里定义以下模式:
$Item$.Price
仅用于写入用法:
$Item$.Price = $exp$;
或仅供阅读使用:
$exp$ = $Item$.Price
where $Item$应该是表达式占位符,选择"Bicycle"类型,不要忘记选中"Exactly this type".
$ exp $可以保持未定义