感谢您的回复。我将尝试在此处解释代码。
[SetUp]
public void SetUp()
{
zones = new ShimZones(new List[I]());
IZone zone = new Zone("1", "306406", "H");
zones.addZone(zone);
}
ShimZones是一个从普通Zones类继承的对象,它只是重写了一个序列化方法,这是我第一次遇到这个问题。这就是我的工作。
Zones 对象几乎只是一个包含 Zone 对象列表的类,具有一些用于操作该列表的帮助器方法。
[代码 1]
这是为要添加的区域项而调用的构造函数。
在我的非测试代码中,在将新区域添加到Zones对象后,我运行此方法
public void UpdateColor()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm = db.TransactionManager;
using (DocumentLock doclock = doc.LockDocument())
using (Transaction tr = tm.StartTransaction())
{
ObjectId newObjectId = this.GetObjectId();
Polyline btr = (Polyline)tr.GetObject(newObjectId, OpenMode.ForWrite);
btr.Color = Autodesk.AutoCAD.Colors.Color.FromColorIndex(ColorMethod.ByAci, (short)color);
tr.Commit();
}
}
但是这似乎是发生崩溃和错误的地方。但是当我运行这个测试方法
[Test]
[Description("Does renumbering the zone work?")]
public void zone_renumber_to_2()
{
zones.RenumberZone(0, "2", "H");
Assert.IsTrue(zones.zoneList[0].zoneNum == "2");
Assert.IsTrue(zones.zoneList[0].color == 116);
}
public void RenumberZone(int index, string newNum, string newThermo)
{
zoneList[index].zoneNum = newNum;
zoneList[index].thermostat = newThermo.ToUpper();
zoneList[index].color = Zone.getZoneColor(this, newNum);
zoneList[index].UpdateColor();
SerializeZones();
}
时,UpdateColor()方法运行没有问题,并且表示Zone的pline的颜色发生了变化?
非常奇怪的行为,一种方法能够毫无问题地运行 UpdateColor() 方法,而另一种方法则无法运行。