从基础实体中查找属性的使用 [英] Find usage of property from base entity
问题描述
我试图在属性属于基类的类中查找属性的用法.这是一个令牌示例:
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);
}
}
如果我只想在自行车项目中找到 Price 的用法,我发现我不走运.我在 Visual Studio 2013 中使用 re-sharper,Find Usage 找到 Price 的所有用法,包括 Book 中的用法.这是一个小示例,但由于基类在许多其他类中使用,因此无法跟踪使用情况.
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.
推荐答案
对于这种情况,ReSharper 的 SRP (Search and Replace with Pattern) 非常有用.
For this case is very usefull the ReSharper's SRP (Search and Replace with Pattern).
Menu Resharper->Find->Search with Pattern...
Menu Resharper->Find->Search with Pattern...
在这里定义以下模式:
$Item$.Price
仅用于写入用途:
$Item$.Price = $exp$;
或仅用于读取用途:
$exp$ = $Item$.Price
其中 $Item$
应该是表达式占位符,选择类型自行车"并且不要忘记选中正是这种类型".
where $Item$
should be an expression placeholder, select the type "Bicycle"
and don't forget to check "Exactly this type".
$exp$ 可以保持未定义
The $exp$ can stay undefined
这篇关于从基础实体中查找属性的使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!