ContextAttribute与ContextBoundObject应用的探究

这两天因开发的需要,需要分析和构建针对ContextAttribute极其ContextBoundContext相关的拦截器的内容,所以今天一上班就开发分析ContextAttribute与ContextBoundContext之间的应用关系,在查看了相关网友的资源后开始了我的分析之路。
  首先:我建立了一个ContextAttribute的子类和一个普通的Attribute子类,分别附加在ContextBoundContext子类和普通子类上。代码如下:

ContextAttribute与ContextBoundObject应用的探究using System;
ContextAttribute与ContextBoundObject应用的探究using System.Collections.Generic;
ContextAttribute与ContextBoundObject应用的探究using System.Text;
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究using System.Runtime.Remoting.Contexts;
ContextAttribute与ContextBoundObject应用的探究using System.Runtime.Remoting.Activation;
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究namespace ContextDemo
ContextAttribute与ContextBoundObject应用的探究ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究    public class DemoContextAttribute : ContextAttribute
ContextAttribute与ContextBoundObject应用的探究    ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        public DemoContextAttribute()
ContextAttribute与ContextBoundObject应用的探究            : base("DemoContextAttribute")
ContextAttribute与ContextBoundObject应用的探究        ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextAttribute' - 'Constructor' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究    public class NonContextAttribute : Attribute
ContextAttribute与ContextBoundObject应用的探究    ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        public NonContextAttribute()
ContextAttribute与ContextBoundObject应用的探究        ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'NonContextAttribute' - 'Constructor' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究    [DemoContext]
ContextAttribute与ContextBoundObject应用的探究    [NonContext]
ContextAttribute与ContextBoundObject应用的探究    public class DemoContextBoundObject : ContextBoundObject
ContextAttribute与ContextBoundObject应用的探究    ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        public DemoContextBoundObject()
ContextAttribute与ContextBoundObject应用的探究        ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextBoundObject' - 'Constructor' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究    [DemoContext]
ContextAttribute与ContextBoundObject应用的探究    [NonContext]
ContextAttribute与ContextBoundObject应用的探究    public class NonContextBoundObject
ContextAttribute与ContextBoundObject应用的探究    ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        public NonContextBoundObject()
ContextAttribute与ContextBoundObject应用的探究        ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'NonContextBoundObject' - 'Constructor' ContextAttribute与ContextBoundObject应用的探究 ");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究    class Program
ContextAttribute与ContextBoundObject应用的探究    ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        static void Main(string[] args)
ContextAttribute与ContextBoundObject应用的探究        ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Begin Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究            DemoContextBoundObject dcbo = new DemoContextBoundObject();
ContextAttribute与ContextBoundObject应用的探究            NonContextBoundObject ncbo = new NonContextBoundObject();
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("End Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究            Console.Read();
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究}
ContextAttribute与ContextBoundObject应用的探究 执行的结果如下:
ContextAttribute与ContextBoundObject应用的探究
这里可以看出,只有继承于ContextAttribute的子类在ContextBoundObject上使用才会进行构造。其实都没有进行调用。
 然后:我将ContextAttribute之下的虚方法都进行了一次继承并且添加相应的查看信息来分析各个方法的调用顺序,代码如下:
ContextAttribute与ContextBoundObject应用的探究using System;
ContextAttribute与ContextBoundObject应用的探究using System.Collections.Generic;
ContextAttribute与ContextBoundObject应用的探究using System.Text;
ContextAttribute与ContextBoundObject应用的探究using System.Runtime.Remoting.Contexts;
ContextAttribute与ContextBoundObject应用的探究using System.Runtime.Remoting.Activation;
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究namespace ContextDemo ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究    public class DemoContextAttribute : ContextAttribute ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        public DemoContextAttribute()
ContextAttribute与ContextBoundObject应用的探究            : base("DemoContextAttribute") ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextAttribute' - 'Constructor' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究        public override void Freeze(Context newContext) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextAttribute' - 'Freeze' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究        public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextAttribute' - 'GetPropertiesForNewContext' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            base.GetPropertiesForNewContext(ctorMsg);
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究        public override bool IsContextOK(Context ctx, IConstructionCallMessage ctorMsg) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextAttribute' - 'IsContextOK' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            return false;
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究        public override bool IsNewContextOK(Context newCtx) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextAttribute' - 'IsNewContextOK' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            return base.IsNewContextOK(newCtx);
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究    [DemoContext]
ContextAttribute与ContextBoundObject应用的探究    public class DemoContextBoundObject : ContextBoundObject ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        public DemoContextBoundObject() ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextBoundObject' - 'Constructor' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究    class Program ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        static void Main(string[] args) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Begin Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            new DemoContextBoundObject();
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("End Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            Console.Read();
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究}
ContextAttribute与ContextBoundObject应用的探究
执行的结果显示如下:
ContextAttribute与ContextBoundObject应用的探究
这里可能以看出在执行的过程中,先建立与ContextBoundObject相关的ContextAttribute对象。并且向ContextAttribute对象询间IsContextOK,环境怎么样还可以吗。这里我先从这个IsContextOK开始进行分析。
这里通过修改代码查看运行的结果发现IsContextOk返回的结果为False,表示对当前环境有点不满意啊,将这里的IsContextOK直接返回True会是什么情况呢。修改代码执行显示结果如下:
ContextAttribute与ContextBoundObject应用的探究 public override bool IsContextOK(Context ctx, IConstructionCallMessage ctorMsg) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextAttribute' - 'IsContextOK' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            return true;
ContextAttribute与ContextBoundObject应用的探究        } ContextAttribute与ContextBoundObject应用的探究
看来这个方式就是用来确认当前环境是否满足要求的,如果满足则不执行。这里可以查看一下这一部分的过程:
   CRL先询问当前环境是否满足要求,如果满足则不继续执行,如果不满足则先初始化新环境的GetPropertiesForNewContext,再将其Freeze,再询问IsNewContextOK如果没有问题则成功,如果在这里返回false,将引发一个Remoting的异常。

 

出处:https://www.cnblogs.com/jeffwoot/archive/2008/05/19/1202427.html

=======================================================================================

昨天了解了ContextAttribute与ContextBoundObject应用开发的一些基础,今天准备在ContextBoundObject对象之上加入消息拦截器,来测试一下应用。
 经过昨天了学习了解到ContextAttribute与ContextBoundObject这一组对象之间的核心关系为:
   IContextAttribute:用于标识上下文环境相关Attribute,当CLR在创建MarshalByRefObject对象时会先查看对象是否包括:IContextAttribute特性,如果存在则询问IContextAttribute.IsContextOK来查询是否需要新的上下文环境,如果返回false则表示需要创建新的上下文环境,并且调用GetPropertiesForNewContext来设计新环境的属性。
   IContextProperty:用于标识上下文环境的属性,可以在GetPropertysForNewContext向新的上下文环境中添加新的自定义属性。
   IContributeObjectSink:如果需要向上下文环境中添加自定义的消息拦截器,由需要IContextProperty的实现对象同时实现本接口。
   还有更多的XXXObjectSink:如果实现也实现相应的消息接收,这里暂不考虑。
注意:如果IContextAttribute附加的对象没有继承自MarshalByRefObject则附加的IContextAttribute会与普通特性一样,不会产生新的上环境文环境。
   了解这一核心关系后,再回过来看昨天所编写的代码,发现其实ConextAttribute已实现IContextAttribute, IContextProperty两个接口。这里所需要添加的只是需要DemoContextAttribute实现IContributeObjectSink接口,并且添加新的消息拦截器。修改后的代码为:

ContextAttribute与ContextBoundObject应用的探究using System;
ContextAttribute与ContextBoundObject应用的探究using System.Collections.Generic;
ContextAttribute与ContextBoundObject应用的探究using System.Text;
ContextAttribute与ContextBoundObject应用的探究using System.Runtime.Remoting.Contexts;
ContextAttribute与ContextBoundObject应用的探究using System.Runtime.Remoting.Activation;
ContextAttribute与ContextBoundObject应用的探究using System.Runtime.Remoting.Messaging;
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究namespace ContextDemo ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究    public class DemoContextAttribute : ContextAttribute, IContributeObjectSink ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        public DemoContextAttribute()
ContextAttribute与ContextBoundObject应用的探究            : base("DemoContextAttribute") ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextAttribute' - 'Constructor' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究        public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextAttribute' - 'GetObjectSink' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究            return new DemoMessageSink(nextSink);
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究    public class DemoMessageSink : IMessageSink ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        public DemoMessageSink(IMessageSink nextSink) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoMessageSink' - 'Constructor' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            this.nextSink = nextSink;
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究        public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            // 暂不考虑
ContextAttribute与ContextBoundObject应用的探究            return null;
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究        private IMessageSink nextSink = null;
ContextAttribute与ContextBoundObject应用的探究        public IMessageSink NextSink ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            get ContextAttribute与ContextBoundObject应用的探究{ return nextSink; }
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究        public IMessage SyncProcessMessage(IMessage msg) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call Begin 'DemoMessageSink' - 'SyncProcessMessage' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究            IMessage returnMsg = nextSink.SyncProcessMessage(msg);
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call End 'DemoMessageSink' - 'SyncProcessMessage' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究            return returnMsg;
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究    [DemoContext]
ContextAttribute与ContextBoundObject应用的探究    public class DemoContextBoundObject : ContextBoundObject ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        public DemoContextBoundObject() ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextBoundObject' - 'Constructor' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究        public void CallMethod() ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call 'DemoContextBoundObject' - 'Call Method' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究
ContextAttribute与ContextBoundObject应用的探究    class Program ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究        static void Main(string[] args) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Begin Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            new DemoContextBoundObject().CallMethod();
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("End Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            Console.Read();
ContextAttribute与ContextBoundObject应用的探究        }
ContextAttribute与ContextBoundObject应用的探究    }
ContextAttribute与ContextBoundObject应用的探究}
ContextAttribute与ContextBoundObject应用的探究

执行后的结果为
ContextAttribute与ContextBoundObject应用的探究

查看结果了解到,获取消息拦截器的操作是在调用方法操作后才进行了,那么如果我在这里调用两次操作,是否会产生两次获取消息消息拦截器的操作呢。这里我将Main()操作修改如下:

ContextAttribute与ContextBoundObject应用的探究 static void Main(string[] args) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Begin Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            DemoContextBoundObject dcbo = new DemoContextBoundObject();
ContextAttribute与ContextBoundObject应用的探究            dcbo.CallMethod();
ContextAttribute与ContextBoundObject应用的探究            dcbo.CallMethod();
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("End Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            Console.Read();
ContextAttribute与ContextBoundObject应用的探究        }

显示的结果如下:
ContextAttribute与ContextBoundObject应用的探究
 这里可以看出只调用了一次获取消息拦截器的操作,多次SyncProcessMessage方法的调用,这个同样适用多方法,可以自行再添加一个CallMethod2方法进行测试,效果是一样的。

那么我又想如果这里生成两个对象并且调用同一个方法又会产生什么结果呢。Main()方法修改如下:

ContextAttribute与ContextBoundObject应用的探究static void Main(string[] args) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Begin Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            new DemoContextBoundObject().CallMethod();
ContextAttribute与ContextBoundObject应用的探究            new DemoContextBoundObject().CallMethod();
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("End Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            Console.Read();
ContextAttribute与ContextBoundObject应用的探究        } 最后的结果显示为:
ContextAttribute与ContextBoundObject应用的探究
和想像中的一样,调用了两次生成Sink的过程。 我又想如果在消息拦截的过程中引发了异常将会也现什么总是呢。于是我再次DemoObjectSink的代码修改如下:
ContextAttribute与ContextBoundObject应用的探究   public IMessage SyncProcessMessage(IMessage msg) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call Begin 'DemoMessageSink' - 'SyncProcessMessage' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            throw new Exception("I'm a exception");
ContextAttribute与ContextBoundObject应用的探究            IMessage returnMsg = nextSink.SyncProcessMessage(msg);
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Call End 'DemoMessageSink' - 'SyncProcessMessage' ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            return returnMsg;
ContextAttribute与ContextBoundObject应用的探究        } 并且将Main()的代码修改如下:
ContextAttribute与ContextBoundObject应用的探究 static void Main(string[] args) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究            Console.WriteLine("Begin Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            try ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究                new DemoContextBoundObject().CallMethod();
ContextAttribute与ContextBoundObject应用的探究                Console.WriteLine("End Main ContextAttribute与ContextBoundObject应用的探究");
ContextAttribute与ContextBoundObject应用的探究            }
ContextAttribute与ContextBoundObject应用的探究            catch (Exception ex) ContextAttribute与ContextBoundObject应用的探究{
ContextAttribute与ContextBoundObject应用的探究                Console.WriteLine("Raise Exeption Message:{0}", ex.Message);
ContextAttribute与ContextBoundObject应用的探究            }
ContextAttribute与ContextBoundObject应用的探究            Console.Read();
ContextAttribute与ContextBoundObject应用的探究        } 执行的结果如下:
ContextAttribute与ContextBoundObject应用的探究
这里可以发现执行的结果与在方法中执行时产生异常的形式是相同的,已是我就要如果用这种方式来进行安全检查会不会得以实现呢?

 

出处:https://www.cnblogs.com/jeffwoot/archive/2008/05/20/1203174.html

=======================================================================================

 

上一篇:vivo Y76s参数配置


下一篇:xiandai客服语音系统 voip相关