/// <summary> /// mock emit code /// </summary> /// <param name="i"></param> /// <returns></returns> public virtual int MockAopTest(int i) { int result = 0; MethodContext context = new MethodContext(); context.ClassName = "AopTestClass"; context.MethodName = "MockAopTest"; context.Executor = this; context.Parameters = new object[1]; context.Parameters[0] = i; context.Processed = false; context.ReturnValue = result; ICallHandler[] handlers = new ICallHandler[1]; NameValueCollection attrCollection = new NameValueCollection(); attrCollection.Add("CacheKey", "TestKey"); attrCollection.Add("DurationMinutes", "35"); handlers[0] = new CacheCallHandler(attrCollection); for (int c = 0; c < handlers.Length; ++c) { handlers[c].BeginInvoke(context); } if (context.Processed == false) { try { result = TestMethod2(i); context.ReturnValue = result; } catch (Exception ex) { context.Exception = ex; for (int c = 0; c < handlers.Length; ++c) { handlers[c].OnException(context); } } } for (int c = 0; c < handlers.Length; ++c) { handlers[c].EndInvoke(context); } return result; }
public void EndInvoke(MethodContext context) { }
public void OnException(MethodContext context) { //Console.WriteLine(context.Exception.Message); }
public void BeginInvoke(MethodContext context) { //context.ReturnValue = "Cache Result"; //context.Processed = true; }