日期:2014-05-20 浏览次数:21082 次
首先是一个用于测试的类,类中有个做标志的静态变量。
    public class RqTest {
        public static bool Rq = false;
        public bool test() 
        {
            return Rq;
        }
    }
 public class CAL
    {
       private DoctMoon doc = new DoctMoon();
        public delegate bool Execute();
        public string Save(Execute ex)
        {
            string msg = string.Empty;
            if(ex()){
                msg += "CAL 成功执行指令\n";
            }
            else
            {
                msg+="CAL 被入侵,DocMoon医生对CAL进行了检测和修复!-修改结果为:"+doc.Fix().ToString()+"\n";
                msg += "CAL 再次执行,执行结果为:" + ex().ToString() + "\n";
            }
            return msg;
        }
        public class DoctMoon:IFix
        {
            public bool Fix()
            {
                RqTest.Rq = true;
                return true;
            }
        }
    }
        static void Main(string[] args)
        {
            //RqTest.Rq = true;//此数据为初始需要的数据,如果true则,CAL可以成功执行,如果false,CAL执行失败,由DoctMoon修复。
            CAL.CAL cal = new CAL.CAL();
            Console.WriteLine(cal.Save(new CAL.RqTest().test));
            Console.ReadKey();
        }