Ejemplo n.º 1
0
        static object DefaultAspectHandler(object targetObject,
			MethodBase method,
			object[] parameters,
			AspectAttribute[] attributes)
        {
            object returnValue;
            InsteadAttribute instead = null;

            foreach (AspectAttribute b in attributes)
            {
                if (b is BeforeAttribute)
                    b.Action(targetObject, method, parameters, null);
                else if (b is InsteadAttribute)
                    instead = (InsteadAttribute)b;
            }
            if (instead != null)
                returnValue = instead.Action(targetObject,method,parameters,null);
            else
                returnValue = targetObject.GetType().GetMethod(method.Name,GetParameterTypes(method)).
                    Invoke(targetObject,parameters);

            //         Una acción After puede necesitar del resultado de haber evaluado el
            //         método por eso se le pasa returnValue
            foreach (AspectAttribute a in attributes)
                if (a is AfterAttribute)
                    a.Action(targetObject, method, parameters, returnValue);

            return returnValue;
        }
Ejemplo n.º 2
0
 public static AspectAttribute[] AspectUnion(AspectAttribute[] asp1, AspectAttribute[] asp2)
 {
     int i;
      AspectAttribute[] aspResult = new AspectAttribute[asp1.Length + asp2.Length];
      for (i=0; i < asp1.Length; i++)
      aspResult[i] = asp1[i];
       for (int j=0; j<asp2.Length; j++)
       aspResult[i+j] = asp2[j];
       return aspResult;
 }