当前位置: 首页 > news >正文

利用消息机制实现.NET AOP(面向方面编程)--利用ServerContextSink实现多截获

以下代码实现利用ServerContextSink来实现多截获

None.gif // 框架代码

None.gif // ObjectWithAspect.cs
None.gif using  System;
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Framework
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    [ObjectSinkChain]
InBlock.gif    
public abstract class ObjectWithAspects:ContextBoundObject
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

None.gif // ServerContextSinkChainProperty.cs
None.gif using  System;
None.gif
using  System.Runtime.Remoting;
None.gif
using  System.Runtime.Remoting.Activation;
None.gif
using  System.Runtime.Remoting.Contexts;
None.gif
using  System.Runtime.Remoting.Messaging;
None.gif
using  System.Runtime.Remoting.Proxies;
None.gif
using  System.Runtime.Remoting.Services;
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Framework
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    [Serializable]
InBlock.gif    
class ServerContextSinkChainProperty:
InBlock.gif        IContextProperty,
InBlock.gif        
//IContributeObjectSink,  //如果不需捕获构造函数,则可使用ObjectSink
InBlock.gif
        IContributeServerContextSink //如果构造函数也要捕获,则使用ServerContextSink
ExpandedSubBlockStart.gifContractedSubBlock.gif
    dot.gif{
InBlock.gif        
string _name;
InBlock.gif        Type _type;
InBlock.gif
InBlock.gif        
public ServerContextSinkChainProperty(Type type,string name)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _name 
= name;
InBlock.gif            _type 
= type;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
private AspectAttribute[] GetAspectAttributes(Type type)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return (AspectAttribute[])_type.GetCustomAttributes(typeof(AspectAttribute), true);
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
IContextProperty 成员#region IContextProperty 成员
InBlock.gif
InBlock.gif        
public void Freeze(Context newContext)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public bool IsNewContextOK(Context newCtx)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return true;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public string Name
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _name; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
IContributeObjectSink 成员#region IContributeObjectSink 成员
InBlock.gif
InBlock.gif        
public IMessageSink GetObjectSink(MarshalByRefObject obj, IMessageSink nextSink)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif
InBlock.gif            AspectAttribute[] sinks 
= GetAspectAttributes(_type);
InBlock.gif            
for (int i = 0; i < sinks.Length; i++ )
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                AspectAttribute aspectAttribute 
= sinks[i];
InBlock.gif                nextSink 
= aspectAttribute.CreateAspectSink(nextSink);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return nextSink;
InBlock.gif            
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
IContributeServerContextSink 成员#region IContributeServerContextSink 成员
InBlock.gif
InBlock.gif        
public IMessageSink GetServerContextSink(IMessageSink nextSink)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            AspectAttribute[] sinks 
= GetAspectAttributes(_type);
InBlock.gif            
for (int i = 0; i < sinks.Length; i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                AspectAttribute aspectAttribute 
= sinks[i];
InBlock.gif                nextSink 
= aspectAttribute.CreateAspectSink(nextSink);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return nextSink;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

None.gif // ServerContextSinkChainAttribute.cs
None.gif using  System;
None.gif
using  System.Runtime.Remoting;
None.gif
using  System.Runtime.Remoting.Activation;
None.gif
using  System.Runtime.Remoting.Contexts;
None.gif
using  System.Runtime.Remoting.Messaging;
None.gif
using  System.Runtime.Remoting.Proxies;
None.gif
using  System.Runtime.Remoting.Services;
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Framework
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    [AttributeUsage(AttributeTargets.Class)]
InBlock.gif    
class ObjectSinkChainAttribute:ContextAttribute
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public ObjectSinkChainAttribute()
InBlock.gif            : 
base("ServerContextSink_Framework_ObjectSinkChainAttribute")
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public override void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Type type 
= ctorMsg.ActivationType;
InBlock.gif            ctorMsg.ContextProperties.Add(
new ServerContextSinkChainProperty(type,this.AttributeName));
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public override bool IsContextOK(Context ctx, IConstructionCallMessage ctorMsg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return (ctx.GetProperty(this.AttributeName) != null );
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

None.gif // AsyncReplyHelperSink.cs
None.gif using  System;
None.gif
using  System.Runtime.Remoting;
None.gif
using  System.Runtime.Remoting.Activation;
None.gif
using  System.Runtime.Remoting.Contexts;
None.gif
using  System.Runtime.Remoting.Messaging;
None.gif
using  System.Runtime.Remoting.Proxies;
None.gif
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Framework
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
class AsyncReplyHelperSink : IMessageSink
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public delegate IMessage AsyncReplyHelperSinkDelegate(IMessage msg);
InBlock.gif
InBlock.gif        IMessageSink _nextSink 
= null;
InBlock.gif        AsyncReplyHelperSinkDelegate _delegate 
= null;
InBlock.gif
InBlock.gif        
public AsyncReplyHelperSink(IMessageSink nextSink, AsyncReplyHelperSinkDelegate delegates)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _nextSink 
= nextSink;
InBlock.gif            _delegate 
= delegates;
ExpandedSubBlockEnd.gif        }

InBlock.gif
ContractedSubBlock.gifExpandedSubBlockStart.gif        
IMessageSink 成员#region IMessageSink 成员
InBlock.gif
InBlock.gif        
public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return null;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public IMessageSink NextSink
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
get dot.gifreturn _nextSink; }
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public IMessage SyncProcessMessage(IMessage msg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
if (_delegate == null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return new ReturnMessage(new Exception("没有处理消息委拖"), (IMethodCallMessage)msg);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                IMessage back 
= _delegate(msg);
InBlock.gif                
return _nextSink.SyncProcessMessage(back);
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

 

None.gif // AspectAttribute.cs
None.gif using  System;
None.gif
using  System.Runtime.Remoting;
None.gif
using  System.Runtime.Remoting.Activation;
None.gif
using  System.Runtime.Remoting.Contexts;
None.gif
using  System.Runtime.Remoting.Messaging;
None.gif
using  System.Runtime.Remoting.Proxies;
None.gif
using  System.Runtime.Remoting.Services;
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Framework
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public abstract class AspectAttribute:Attribute
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public abstract IMessageSink CreateAspectSink(IMessageSink nextSink);
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

None.gif // Demo代码

None.gif // Program.cs
None.gif using  System;
None.gif
None.gif
using  DotNetAOP.ServerContextSink.Framework;
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Demo
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
ExpandedSubBlockStart.gifContractedSubBlock.gif    
/**//// <summary>
InBlock.gif    
/// Class1 的摘要说明。
ExpandedSubBlockEnd.gif    
/// </summary>

InBlock.gif    class Program
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
/**//// <summary>
InBlock.gif        
/// 应用程序的主入口点。
ExpandedSubBlockEnd.gif        
/// </summary>

InBlock.gif        [STAThread]
InBlock.gif        
static void Main(string[] args)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            Calculator calc 
= new Calculator();
InBlock.gif            Console.WriteLine(calc.Add(
1,2));
InBlock.gif            Console.WriteLine(calc.Divide(
2,0));
InBlock.gif
//            Test2 t2 = new Test2();
InBlock.gif
//            t2.Te();
InBlock.gif
            Console.ReadLine();
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

None.gif // LogSinkAttribute.cs
None.gif using  System;
None.gif
using  System.Runtime.Remoting;
None.gif
using  System.Runtime.Remoting.Activation;
None.gif
using  System.Runtime.Remoting.Contexts;
None.gif
using  System.Runtime.Remoting.Messaging;
None.gif
using  System.Runtime.Remoting.Proxies;
None.gif
using  System.Runtime.Remoting.Services;
None.gif
None.gif
using  DotNetAOP.ServerContextSink.Framework;
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Demo
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    [AttributeUsage(AttributeTargets.Class)]
InBlock.gif    
public class LogSinkAttribute:AspectAttribute
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public override IMessageSink CreateAspectSink(IMessageSink nextSink)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return new LogSink(nextSink);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

None.gif // LogSink.cs
None.gif using  System;
None.gif
using  System.Runtime.Remoting;
None.gif
using  System.Runtime.Remoting.Activation;
None.gif
using  System.Runtime.Remoting.Contexts;
None.gif
using  System.Runtime.Remoting.Messaging;
None.gif
using  System.Runtime.Remoting.Proxies;
None.gif
using  System.Runtime.Remoting.Services;
None.gif
None.gif
using  DotNetAOP.ServerContextSink.Framework;
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Demo
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public class LogSink:IMessageSink
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
readonly IMessageSink _nextSink;
InBlock.gif        
public LogSink(IMessageSink nextSink)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _nextSink 
= nextSink;
ExpandedSubBlockEnd.gif        }

ContractedSubBlock.gifExpandedSubBlockStart.gif        
IMessageSink 成员#region IMessageSink 成员
InBlock.gif
InBlock.gif        
public IMessage SyncProcessMessage(IMessage msg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            IMethodCallMessage call 
= msg as IMethodCallMessage;
InBlock.gif            IConstructionCallMessage ctr 
= call as IConstructionCallMessage;
InBlock.gif
InBlock.gif            IMethodReturnMessage back 
= null;
InBlock.gif            
if(ctr != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Console.WriteLine(
"构造函数:\t"+ctr.MethodName);
InBlock.gif                back 
= (IMethodReturnMessage)NextSink.SyncProcessMessage(msg);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Console.WriteLine(
"普通方法:\t" + call.MethodName);
InBlock.gif                back 
= (IMethodReturnMessage)NextSink.SyncProcessMessage(msg);
InBlock.gif                
bool exception = false;
InBlock.gif                
if(back.ReturnValue is double)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    
if(double.IsInfinity((double)back.ReturnValue))
InBlock.gif                        exception 
= true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
if!exception)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    exception 
= (back.Exception != null);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
if(!exception)
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Console.WriteLine(
"返回结果为:"+back.ReturnValue);
ExpandedSubBlockEnd.gif                }

InBlock.gif                
else
ExpandedSubBlockStart.gifContractedSubBlock.gif                
dot.gif{
InBlock.gif                    Console.WriteLine(
"出现异常了:\t"+back.ReturnValue);
InBlock.gif                    back 
= new ReturnMessage(1.0,null,0,back.LogicalCallContext,call);
ExpandedSubBlockEnd.gif                }

ExpandedSubBlockEnd.gif            }

InBlock.gif            
return back;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public IMessageSink NextSink
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _nextSink;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            AsyncReplyHelperSink.AsyncReplyHelperSinkDelegate asd 
= new AsyncReplyHelperSink.AsyncReplyHelperSinkDelegate(AsyncProcessMessage);
InBlock.gif
InBlock.gif            replySink 
= new AsyncReplyHelperSink(replySink, asd);
InBlock.gif
InBlock.gif            
if (_nextSink != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _nextSink.AsyncProcessMessage(msg, replySink);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return null;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
private IMessage AsyncProcessMessage(IMessage msg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            IMethodCallMessage call 
= msg as IMethodCallMessage;
InBlock.gif            IConstructionCallMessage ctr 
= call as IConstructionCallMessage;
InBlock.gif            
if (ctr != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Console.WriteLine(
"构造函数:\t" + ctr.MethodName);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Console.WriteLine(
"普通方法:\t" + call.MethodName);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return msg;
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

None.gif // Log2Sink.cs
None.gif using  System;
None.gif
using  System.Runtime.Remoting;
None.gif
using  System.Runtime.Remoting.Activation;
None.gif
using  System.Runtime.Remoting.Contexts;
None.gif
using  System.Runtime.Remoting.Messaging;
None.gif
using  System.Runtime.Remoting.Proxies;
None.gif
using  System.Runtime.Remoting.Services;
None.gif
None.gif
using  DotNetAOP.ServerContextSink.Framework;
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Demo
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    
public class Log2Sink : IMessageSink
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
readonly IMessageSink _nextSink;
InBlock.gif        
public Log2Sink(IMessageSink nextSink)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            _nextSink 
= nextSink;
ExpandedSubBlockEnd.gif        }

ContractedSubBlock.gifExpandedSubBlockStart.gif        
IMessageSink 成员#region IMessageSink 成员
InBlock.gif
InBlock.gif        
public IMessage SyncProcessMessage(IMessage msg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            IMethodCallMessage call 
= msg as IMethodCallMessage;
InBlock.gif            IConstructionCallMessage ctr 
= call as IConstructionCallMessage;
InBlock.gif
InBlock.gif            IMethodReturnMessage back 
= null;
InBlock.gif
InBlock.gif            Console.WriteLine(
"第二个处理器");
InBlock.gif
InBlock.gif            back 
= (IMethodReturnMessage)NextSink.SyncProcessMessage(msg);
InBlock.gif            
InBlock.gif            
return back;
ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public IMessageSink NextSink
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
get
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _nextSink;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
InBlock.gif        
public IMessageCtrl AsyncProcessMessage(IMessage msg, IMessageSink replySink)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            AsyncReplyHelperSink.AsyncReplyHelperSinkDelegate asd 
= new AsyncReplyHelperSink.AsyncReplyHelperSinkDelegate(AsyncProcessMessage);
InBlock.gif
InBlock.gif            replySink 
= new AsyncReplyHelperSink(replySink, asd);
InBlock.gif
InBlock.gif            
if (_nextSink != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return _nextSink.AsyncProcessMessage(msg, replySink);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                
return null;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif        
#endregion

InBlock.gif
InBlock.gif        
private IMessage AsyncProcessMessage(IMessage msg)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            IMethodCallMessage call 
= msg as IMethodCallMessage;
InBlock.gif            IConstructionCallMessage ctr 
= call as IConstructionCallMessage;
InBlock.gif            
if (ctr != null)
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Console.WriteLine(
"构造函数:\t" + ctr.MethodName);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
else
ExpandedSubBlockStart.gifContractedSubBlock.gif            
dot.gif{
InBlock.gif                Console.WriteLine(
"普通方法:\t" + call.MethodName);
ExpandedSubBlockEnd.gif            }

InBlock.gif            
return msg;
InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif
InBlock.gif    [AttributeUsage(AttributeTargets.Class)]
InBlock.gif    
public class Log2SinkAttribute : AspectAttribute
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public override IMessageSink CreateAspectSink(IMessageSink nextSink)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return new Log2Sink(nextSink);
ExpandedSubBlockEnd.gif        }

InBlock.gif
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

None.gif // Calculator.cs
None.gif using  System;
None.gif
None.gif
using  DotNetAOP.ServerContextSink.Framework;
None.gif
None.gif
namespace  DotNetAOP.ServerContextSink.Demo
ExpandedBlockStart.gifContractedBlock.gif
dot.gif {
InBlock.gif    [LogSink,Log2Sink]
InBlock.gif    
public class Calculator:ObjectWithAspects
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
public Calculator()
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public double Add(double a , double b)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return a + b;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
public double Divide(double a, double b)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            
return a/b;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

None.gif

 

需要上面完整代码请留下Email。

查看其它框架实现请转到此页lucky.gif

利用消息机制实现.NET AOP(面向方面编程)--通过RealProxy实现
利用消息机制实现.NET AOP(面向方面编程)--利用RealProxy和消息接收器实现多截获
利用消息机制实现.NET AOP(面向方面编程)--利用ServerContextSink实现多截获

相关文章:

  • Atlas学习手记(8):调用本地Web Service简单介绍
  • 诊断排除基本的 TCP/IP 网络问题
  • 数学名师沈赫哲----在台大上课的演讲全文!!
  • 针对 xml 数据类型的 XQuery (摘自SQL Server 2005 联机丛书)
  • C#谜题86: 有害的括号垃圾
  • 思科新logo
  • [转载]asp.net中page对象生命周期和各事件执行顺序
  • SQL Server连接中三个常见的错误分析(转)
  • 微软 DLinq技术来临前的国内 .NET 的 ORM 发展之局势
  • 第二篇 收购与发展
  • 一个小网工的笔记1
  • “应用”按钮,一个让人比较郁闷的设计
  • 越来越冷了
  • 闲谈: 测试报告系统
  • 美国SkillSoft巨资收购NETg公司,巩固全球霸主地位
  • [ 一起学React系列 -- 8 ] React中的文件上传
  • AngularJS指令开发(1)——参数详解
  • exif信息对照
  • Golang-长连接-状态推送
  • JS笔记四:作用域、变量(函数)提升
  • Linux编程学习笔记 | Linux IO学习[1] - 文件IO
  • Nacos系列:Nacos的Java SDK使用
  • Promise面试题2实现异步串行执行
  • python学习笔记-类对象的信息
  • seaborn 安装成功 + ImportError: DLL load failed: 找不到指定的模块 问题解决
  • spring security oauth2 password授权模式
  • Synchronized 关键字使用、底层原理、JDK1.6 之后的底层优化以及 和ReenTrantLock 的对比...
  • 搭建gitbook 和 访问权限认证
  • 构建工具 - 收藏集 - 掘金
  • 构造函数(constructor)与原型链(prototype)关系
  • 关键词挖掘技术哪家强(一)基于node.js技术开发一个关键字查询工具
  • 腾讯优测优分享 | Android碎片化问题小结——关于闪光灯的那些事儿
  • 一份游戏开发学习路线
  • 7行Python代码的人脸识别
  • Spring Batch JSON 支持
  • 测评:对于写作的人来说,Markdown是你最好的朋友 ...
  • (173)FPGA约束:单周期时序分析或默认时序分析
  • (Python第六天)文件处理
  • (ZT) 理解系统底层的概念是多么重要(by趋势科技邹飞)
  • (接口自动化)Python3操作MySQL数据库
  • (论文阅读30/100)Convolutional Pose Machines
  • (七)理解angular中的module和injector,即依赖注入
  • (切换多语言)vantUI+vue-i18n进行国际化配置及新增没有的语言包
  • (算法)N皇后问题
  • (转)Groupon前传:从10个月的失败作品修改,1个月找到成功
  • .NET CLR Hosting 简介
  • .net on S60 ---- Net60 1.1发布 支持VS2008以及新的特性
  • .Net(C#)自定义WinForm控件之小结篇
  • .NET/C# 判断某个类是否是泛型类型或泛型接口的子类型
  • .NET开发人员必知的八个网站
  • .Net中的集合
  • ::before和::after 常见的用法
  • @RequestMapping用法详解
  • [ C++ ] 继承
  • [ vulhub漏洞复现篇 ] Apache APISIX 默认密钥漏洞 CVE-2020-13945