1.有一个树形结构,节点类型有package, sequence, section , include ,item ,skip其中itemn还分为TF,MCSS,INFO,ESSAY,CHECK几种类型,要求如下:根节点只能为package;
package下只能放sequence,include,INFO类型
sequence下面只能放section、skip和任意类型的item;
section下面只能放skip和各种类型的item;
item,include,skip下面不能放任何类型;完成类的设计,并写出在节点移动时的进行相应检查的代码2.指出下面类的作用,并写出示例代码
public class Disposable Action :IDisposable{
System.Action _action;
public Disposable Action(System.Action action)
{
if (action == null)
throw new ArgumentNullException("action");
_action =actionpublic void Dispose()
{ _action();}
}
}
package下只能放sequence,include,INFO类型
sequence下面只能放section、skip和任意类型的item;
section下面只能放skip和各种类型的item;
item,include,skip下面不能放任何类型;完成类的设计,并写出在节点移动时的进行相应检查的代码2.指出下面类的作用,并写出示例代码
public class Disposable Action :IDisposable{
System.Action _action;
public Disposable Action(System.Action action)
{
if (action == null)
throw new ArgumentNullException("action");
_action =actionpublic void Dispose()
{ _action();}
}
}
解决方案 »
- 关于使用HttpWebRequest超时的问题
- VC写的动态链接库中的一个函数 如何在C#里声明调用
- c#默认的数字是16进制????
- 快速文本扫描
- 请问:c#如何实现,在数据库中表中设定时间,然后系统到该规定时间时进行提示,如弹出对话框
- [高分-顶者有分]如何实现动态添加TreeView控件的Checkbox功能?
- 怎么样在winform的textbox里的光标处插入文本??
- SOS!紧急求救,关于treeView和ListView的问题,各位大哥大姐们帮帮忙呀
- C#查询access 返回dataset为空?一切语句、方法、设置正确!急!!
- 哪里有支持ASP.net的网络空间????
- 错误信息集
- 窗体 图形 的坐标
第二题的作用应该是对指定Action进行释放资源吧
各位xdjm 我今天考试 是没做完的
2:public Disposable Action(System.Action action) 构造函数错误,而且没有终止符(})。
3: _action(); _action 定义为字段,而非方法。
不知道有没有更好的
public class Disposable_Action :IDisposable {
System.Action _action;
public Disposable_Action(System.Action action)
{
if (action == null)
throw new ArgumentNullException("action");
_action =action public void Dispose()
{ _action();}
}
}
Disposable_Action action=new Disposable_Action(new Action(Run));
action.Dispose();//输出Run
public void Run()
{
Console.WriteLine("Run");
}
而不用显式声明一个自定义的委托来封装此方法。
该封装的方法必须与此委托定义的方法签名相对应。这意味着该方法不得具有参数和返回值。
那就知道该用户自定义的Action类可以自定义执行Dispose时要执行的代码
class item:TreeNode
{
}class TF:item
{
}class MCSS:item
{
}class INFO:item
{
}class ESSAY:item
{
}class CHECK:item
{
}class include :TreeNode
{
}class Skip :TreeNode
{
}class package:TreeNode
{
TreeNode TN;
}class sequence:TreeNode
{
TreeNode TN;
}class section :TreeNode
{
TreeNode TN;
}void MoveNode(TreeNode From,TreeNode InsertBehind)
{
if (InsertBehind is package)
if (!(From is sequence)&&!(From is include)&&!(From is INFO))
throw new Exception("节点类型错误"); if (InsertBehind is sequence)
if (!(From is section)&&!(From is skip)&&!From.IsSubclassOf(item))
throw new Exception("节点类型错误"); if (InsertBehind is section)
if (!(From is skip)&&!From.IsSubclassOf(item))
throw new Exception("节点类型错误");
}
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace TestAOP
{
public class Node
{
static List<String> NoChilden = new List<string>() { "item","include","skip" };
static Dictionary<String, List<String>> AllowedChildresList = new Dictionary<string, List<string>>();
public Node()
{
//允许子级列表
AllowedChildresList.Add("package", new List<string>() { "sequence", "include", "NFO" });
AllowedChildresList.Add("sequence", new List<string>() { "section", "skip", "Itemn" });
AllowedChildresList.Add("section", new List<string>() { "skip", "Itemn" });
AllowedChildresList.Add("Itemn", new List<string>() { "TF", "MCSS", "INFO", "ESSAY", "CHECK" });
Children = new List<Node>();
} public String NodeType
{
get;
set;
}
public Node Parent
{
get;
set;
} List<Node> Children
{
get;
set;
} public Node[] ChildrenArray
{
get
{
return this.Children.ToArray();
}
}
public bool AddChild(Node n)
{
if (this.CanAddChild(n))
{
n.Parent = this;
this.Children.Add(n);
return true;
}
return false;
} public bool CanAddChild(Node n)
{
if (NoChilden.Contains(this.NodeType)) //没有子节点的
{
return false;
}
if (AllowedChildresList["Itemn"].Contains(n.NodeType)) //如果为Itemn 可支持Itemn的子级
{
return AllowedChildresList[this.NodeType].Contains("Itemn");
}
if (AllowedChildresList.ContainsKey(this.NodeType))
{
return AllowedChildresList[this.NodeType].Contains(n.NodeType);
}
return true;
}
}
}
很简单