是的,我看到其他的話題:Visual Studio Debugger - Automatic Variable AssignmentVisual Studio調試器自動變量賦值
但我需要一個解決方案的今天,發現一個之前,我看出來了,我想知道是否有一個更好的在那裏?
我的案例: 我有一個實體列表,我根據很多因素設置了一些策略相關的屬性。但它還沒有實現,或者僅僅是我想在實體有權利和不實現的時候測試用戶界面(儘可能快地改變實際工作)。
因此,我設置實體就好像它有權利,所以我可以用這個來測試UI。但是我不想在列表中的每個元素上打破,並將標誌從true更改爲false(以測試其他情況)。我尋找一種方法來自動從調試器中更改變量。我想出了這個解決方案:
- 設置斷點
- 設置它的條件,這是一個「假」,但它會改變變量的值
- 調試模式運行
- 如果我需要的情況下1.啓用斷點,如果我需要的另一個,我禁用斷點
簡化的例子:
namespace AutoVariable
{
class Program
{
static void Main(string[] args)
{
try
{
new Program().Entrance();
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e.Message);
}
}
public void Entrance()
{
var entities = new List<Entity>
{
new Entity() { Name = "A" },
new Entity() { Name = "B" },
new Entity() { Name = "C" }
};
entities.ForEach(setRight);
entities.ForEach(Console.WriteLine);
}
protected void setRight(Entity entity)
{
//not implemented
bool hasRight = true;
entity.HasRight = hasRight;
}
}
class Entity
{
public bool HasRight { get; set; }
public string Name { get; set; }
public override string ToString()
{
return string.Format("{0} - {1}", Name, HasRight);
}
}
}
我設置了一個條件斷點:entity.HasRight = hasRight;
與此條件:(hasRight = false)
所以hasRight將是錯誤的和斷點從來沒有一炮打響。
但它可以在其他情況下也可以使用,例如在賈森·歐文的帖子,你可以使用這樣的:(userName = "Jason").Length < 1
所以我的問題是它是一個很好的解決方案或我錯過了從「本土的東西'調試器工具集?
在此先感謝!
negra
這一個需要多一點時間來達到相同的結果,但基本上,是的。謝謝。 –