全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
这两天因开发的需要,需要分析和构建针对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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- GB/T 48336.101-2026星闪无线通信系统第101部分:架构和通用要求
- T/ZGZS 0505-2023再生棉纱线产品碳足迹核算方法
- T/HSIPA 025-2022中医拨筋技术操作规范
- T/CISIA 008-2024电子级过硫酸盐
- T/CARD 007-2020智力障碍者用可穿戴定位设备技术要求和测试方法
- T/CSCB 0027-2024人胰岛
- 2025~2026学年内蒙古呼伦贝尔市鄂伦春自治旗人教版六年级下册期末考试数学试卷【附答案】
- 2025~2026学年广东省揭阳市普宁市人教版六年级上册学习评价(二)数学试卷【附答案】
- 2025-2026学年河南省林州市初中政治八年级期末下册自测模拟高分特训题(附答案)
- 2025-2026学年江西省樟树市初中政治八年级期末下册高分预测黑金试卷附答案
- 2026国企招聘考试(法务)历年参考题库含答案详解
- T∕CECS 277-2021 建筑给水排水薄壁不锈钢管连接技术规程(团体标准)
- 2026年天然气分公司人员招聘笔试模拟试题及详细答案解析
- 2026年注册安全工程师考试(中级)安全生产管理试题与参考答案
- 2026年初级会计实务历年真题及答案
- 电工:低压配电系统电气故障诊断详解
- 第五单元 用字母表示数和数量关系 第6节 探秘百数表
- 2026相关方安全生产管理协议书汇编
- 2026年国家电网招聘之管理类通关考试题库带答案解析
- SYT 6150.2-2025《钢制管道封堵技术规范 第2部分:挡板-囊式封堵》
- GB/T 33969-2026高炉富氧喷煤技术规范
评论
0/150
提交评论