这两天因开发的需要,需要分析和构建针对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之下的虚方法都进行了一次继承并且添加相应的查看信息来分析各个方法的调用顺序,代码如下:
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应用开发
这里可能以看出在执行的过程中,先建立与ContextBoundObject相关的ContextAttribute对象。并且向ContextAttribute对象询间IsContextOK,环境怎么样还可以吗。这里我先从这个IsContextOK开始进行分析。
这里通过修改代码查看运行的结果发现IsContextOk返回的结果为False,表示对当前环境有点不满意啊,将这里的IsContextOK直接返回True会是什么情况呢。修改代码执行显示结果如下:
        }
ContextAttribute与ContextBoundObject应用开发
看来这个方式就是用来确认当前环境是否满足要求的,如果满足则不执行。这里可以查看一下这一部分的过程:
   CRL先询问当前环境是否满足要求,如果满足则不继续执行,如果不满足则先初始化新环境的GetPropertiesForNewContext,再将其Freeze,再询问IsNewContextOK如果没有问题则成功,如果在这里返回false,将引发一个Remoting的异常。

相关文章:

  • 2021-11-19
  • 2021-12-08
  • 2021-11-17
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
猜你喜欢
  • 2022-02-18
  • 2022-02-05
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-29
  • 2022-12-23
相关资源
相似解决方案