ContextAttribute与ContextBoundObject应用开发.doc_第1页
ContextAttribute与ContextBoundObject应用开发.doc_第2页
ContextAttribute与ContextBoundObject应用开发.doc_第3页
ContextAttribute与ContextBoundObject应用开发.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

这两天因开发的需要,需要分析和构建针对ContextAttribute极其ContextBoundContext相关的拦截器的内容,所以今天一上班就开发分析ContextAttribute与ContextBoundContext之间的应用关系,在查看了相关网友的资源后开始了我的分析之路。 首先:我建立了一个ContextAttribute的子类和一个普通的Attribute子类,分别附加在ContextBoundContext子类和普通子类上。代码如下: using System; using System.Collections.Generic; using System.Text; using System.Runtime.Remoting.Contexts; using System.Runtime.Remoting.Activation; namespace ContextDemo public class DemoContextAttribute : ContextAttribute public DemoContextAttribute() : base ( DemoContextAttribute ) Console.WriteLine( Call DemoContextAttribute - Constructor ); public class NonContextAttribute : Attribute public NonContextAttribute() Console.WriteLine( Call NonContextAttribute - Constructor ); DemoContext NonContext public class DemoContextBoundObject : ContextBoundObject public DemoContextBoundObject() Console.WriteLine( Call DemoContextBoundObject - Constructor ); DemoContext NonContext public class NonContextBoundObject public NonContextBoundObject() Console.WriteLine( Call NonContextBoundObject - Constructor ); class Program static void Main( string args) Console.WriteLine( Begin Main ); DemoContextBoundObject dcbo = new DemoContextBoundObject(); NonContextBoundObject ncbo = new NonContextBoundObject(); Console.WriteLine( End Main ); Console.Read(); 执行的结果如下: 这里可以看出,只有继承于ContextAttribute的子类在ContextBoundObject上使用才会进行构造。其实都没有进行调用。然后: 我将ContextAttribute之下的虚方法都进行了一次继承并且添加相应的查看信息来分析各个方法的调用顺序,代码如下: using System; using System.Collections.Generic; using System.Text; using System.Runtime.Remoting.Contexts; using System.Runtime.Remoting.Activation; namespace ContextDemo public class DemoContextAttribute : ContextAttribute public DemoContextAttribute() : base ( DemoContextAttribute ) Console.WriteLine( Call DemoContextAttribute - Constructor ); public override void Freeze(Context newContext) Console.WriteLine( Call DemoContextAttribute - Freeze ); public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg) Console.WriteLine( Call DemoContextAttribute - GetPropertiesForNewContext ); base .GetPropertiesForNewContext(ctorMsg); public override bool IsContextOK(Context ctx, IConstructionCallMessage ctorMsg) Console.WriteLine( Call DemoContextAttribute - IsContextOK ); return false ; public override bool IsNewContextOK(Context newCtx) Console.WriteLine( Call DemoContextAttribute - IsNewContextOK ); return base .IsNewContextOK(newCtx); DemoContext public class DemoContextBoundObject : ContextBoundObject public DemoContextBoundObject() Console.WriteLine( Call DemoContextBoundObject - Constructor ); class Program static void Main( string args) Console.WriteLine( Begin Main ); new DemoContextBoundObject(); Console.WriteLine( End Main ); Console.Read(); 执行的结果显示如下: 这里可能以看出在执行的过程中,先建立与ContextBoundObject相关的ContextAttribute对象。并且向 ContextAttribute对象询间IsContextOK,环境怎么样还可以吗。这里我先从这个IsContextOK开始进行分析。这里通过修改代码查看运行的结果发现IsContextOk返回的结果为False,表示对当前环境有点不满意啊,将这里的IsContextOK直接返回True会是什么情况呢。修改代码执行显示结果如下:public override bool IsContextOK(Context ctx, IConstructionCallMessage ctorMsg) Console.WriteLine( Call DemoContextAttribute - IsContextOK ); return true ; 看来这个方式就是用来确认当前环境是否满足要求的,

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论