aspectattribute.cs

来自「应用AOP」· CS 代码 · 共 87 行

CS
87
字号
//
// Write by Peopleyl 2007-04-13
//
using System;
using System.Runtime.Remoting.Contexts;
using System.Runtime.Remoting.Activation;

namespace Aspect.AopBase
{
	[Serializable,AttributeUsage(AttributeTargets.Class|AttributeTargets.Method)]
	public abstract class AspectAttribute:Attribute,IContextAttribute,IContextProperty
	{	
		#region Attribute Member		
		public override bool Equals(object obj)
		{	
			IContextProperty contextProperty = obj as IContextProperty;
			if(contextProperty != null)
			{
				return Name.Equals(contextProperty.Name);
			}
			return false;
		}
		
		public override int GetHashCode()
		{
			return Name.GetHashCode();
		}
		#endregion

		#region IContextProperty Member
		
		public virtual string Name
		{
			get
			{
				return "Aop";
			}
		}

		public virtual bool IsNewContextOK(Context context)
		{
			return true;
		}

		public virtual void Freeze(Context newContext)
		{
			return;
		}

		#endregion

		#region IContextAttribute Member
		
		public void GetPropertiesForNewContext(IConstructionCallMessage ctorMsg)
		{
			if (ctorMsg == null)
			{
				throw new ArgumentNullException("ctorMsg");
			}
			ctorMsg.ContextProperties.Add(GetContextProperty(Name));
		}
		
		public virtual bool IsContextOK(Context context, IConstructionCallMessage ctorCallMsg)
		{
			if(context == null)
				throw new ArgumentNullException("context");

			if(ctorCallMsg == null)
				throw new ArgumentNullException("ctorCallMsg");

			if(!ctorCallMsg.ActivationType.IsContextful)
				return true;

			object obj = context.GetProperty(Name);
			if((obj != null) && this.Equals(obj))
				return true;

			return false;
		}

		public abstract AspectProperty GetContextProperty(string aopName);

		#endregion

	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?