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();}
}
}

解决方案 »

  1.   

    第一题没时间写代码了,主要看你的逻辑思维能力,你仔细想想也能做出来。
    第二题的作用应该是对指定Action进行释放资源吧
      

  2.   

    看来 能做出来的人还是比较少啊。
    各位xdjm 我今天考试 是没做完的
      

  3.   

    1:public class  Disposable  Action :IDisposable 类定义错误。
    2:public Disposable  Action(System.Action action) 构造函数错误,而且没有终止符(})。
    3: _action(); _action 定义为字段,而非方法。
      

  4.   

    第2题已经有人做出来了
    不知道有没有更好的
    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");
            }
      

  5.   

    其实第二题还是比较简单的,关键要知道 System.Action是什么:它只是一个简单的委托,可以使用此委托以参数形式传递一个执行某操作的方法,
    而不用显式声明一个自定义的委托来封装此方法。
    该封装的方法必须与此委托定义的方法签名相对应。这意味着该方法不得具有参数和返回值。
    那就知道该用户自定义的Action类可以自定义执行Dispose时要执行的代码
      

  6.   


    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("节点类型错误");
    }
      

  7.   

    using System;
    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;
            }
        }
    }
      

  8.   

    请参考 TreeNode 的 drag  代码
    很简单