求助,请教下面这个方法的逻辑是否合理

猴头 2014-01-17 10:31:04


/// <summary>
/// 将一个指定的组合图形拆分为多个图形,拆分后的子图形将被设置为【非锁定】和【非选中】状态。
/// </summary>
/// <param name="dGroup">指定要拆分的组合图形</param>
/// <returns>返回一个包含拆分后的子图形的图形列表</returns>
public static List<BaseElement> BreakObj(DrawGroup dGroup)
{
if (dGroup == null)
{
throw new Exception("请确保参数不为null。方法名:[GroupAction.BreakObj];参数:[DrawGroup dGroup]");
}
if (dGroup.children == null)
{
throw new Exception("请确保参数是一个有效的组合图形。方法名:[GroupAction.BreakObj];参数:[DrawGroup dGroup]");
}
if (dGroup.children.Count <= 0)
{
throw new Exception("请确保参数是一个有效的组合图形。方法名:[GroupAction.BreakObj];参数:[DrawGroup dGroup]");
}

for (int i = 0; i < dGroup.children.Count; i++)
{
if (dGroup.children[i] == null)
{
dGroup.children.RemoveAt(i);
i--;
continue;
}
dGroup.children[i].BLock = false;
}
if (dGroup.children.Count <= 0)
{
throw new Exception("请确保参数是一个有效的组合图形。方法名:[GroupAction.BreakObj];参数:[DrawGroup dGroup]");
}

List<BaseElement> eLst = new List<BaseElement>();
for (int i = 0; i < dGroup.children.Count; i++)
{
eLst.Add(dGroup.children[i]);
if (dGroup.children[i] is DrawSignItem)
{
//Do Samething
}
else
{
dGroup.children[i].resetLocation();
}
}
dGroup.locateToChild();
dGroup.children.Clear();
dGroup.Dispose();
for (int i = 0; i < eLst.Count; i++)
{
eLst[i].resetLocation();
eLst[i].BLock = false;
eLst[i].BIsSelected = false;
eLst[i].FGraphUnit = dGroup.FGraphUnit;
}
return eLst;
}



纠结好几天了,确定不下来。
...全文
158 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
猴头 2014-01-17
  • 打赏
  • 举报
回复
引用 5 楼 wanghui0380 的回复:
 for (int i = 0; i < dGroup.children.Count; i++)
            {
                if (dGroup.children[i] == null)
                {
                    dGroup.children.RemoveAt(i);
                    i--;
                    continue;
                }
                dGroup.children[i].BLock = false;
            }
额,我们不知道你到底要怎么保证,所以只能给点技巧性提示,这个代码别扭点,这里有下技巧来着,不要正向循环,i++,i--看滴郁闷啊!这里你负向循环,从结尾开始判定移除,这样就不会影响上面的顺序了
好主意
小猪八Q 2014-01-17
  • 打赏
  • 举报
回复
楼上的建议不错,不过都行,只要自己不被绕糊涂就成。看代码没什么太大的问题,有些判断可以通过||合并起来,减少下代码。
wanghui0380 2014-01-17
  • 打赏
  • 举报
回复
 for (int i = 0; i < dGroup.children.Count; i++)
            {
                if (dGroup.children[i] == null)
                {
                    dGroup.children.RemoveAt(i);
                    i--;
                    continue;
                }
                dGroup.children[i].BLock = false;
            }
额,我们不知道你到底要怎么保证,所以只能给点技巧性提示,这个代码别扭点,这里有下技巧来着,不要正向循环,i++,i--看滴郁闷啊!这里你负向循环,从结尾开始判定移除,这样就不会影响上面的顺序了
F546445693 2014-01-17
  • 打赏
  • 举报
回复
for (int i = 0; i < dGroup.children.Count; i++)             {                 if (dGroup.children[i] == null)                 {                     dGroup.children.RemoveAt(i);                     i--;                     continue;                 }                 dGroup.children[i].BLock = false;             } 如果第1个记录就为空,不会死循环? 既然是空为什么还要去Remove? 有点不明白
  • 打赏
  • 举报
回复
if (dGroup.children == null) { throw new Exception("请确保参数是一个有效的组合图形。方法名:[GroupAction.BreakObj];参数:[DrawGroup dGroup]"); } if (dGroup.children.Count <= 0) { throw new Exception("请确保参数是一个有效的组合图形。方法名:[GroupAction.BreakObj];参数:[DrawGroup dGroup]"); } 我能不能理解为这两句表达的是一个意思
猴头 2014-01-17
  • 打赏
  • 举报
回复
写来写去 还是 不尽人意......
rtdb 2014-01-17
  • 打赏
  • 举报
回复
什么逻辑?什么目标? 什么意思?

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧