public override void OnInvoke(MethodInterceptionArgs args) { args.Arguments[0] = defaultInputParameter; base.OnInvoke(args); //or you can use args.Proceed() args.SetReturnValue(defaultReturnParameter); }
public override void OnInvoke(MethodInterceptionArgs args) { var someTest = args.Arguments[0] as SomeTestClass; someTest.Property = 20; someTest.OtherProperty = 20; args.SetReturnValue(someTest.Property * someTest.OtherProperty); }
public override async Task OnInvokeAsync(MethodInterceptionArgs args) { args.Arguments[0] = defaultInputParameter; await args.ProceedAsync(); //or you can use await base.OnInvokeAsync(args); args.SetReturnValue(defaultReturnParameter); }
public override void OnInvoke(MethodInterceptionArgs args) { if (typeof(ICacheManager).IsAssignableFrom(_cachetype) == false) { throw new Exception("Worn Cache Manager"); } _cacheManager = (ICacheManager)Activator.CreateInstance(_cachetype); var methodName = string.Format("{0}.{1}.{2}", args.Method.ReflectedType.Namespace, args.Method.ReflectedType.Name, args.Method.Name); var arguments = args.Arguments.ToList(); var key = string.Format("{0}({1})", methodName, string.Join(",", arguments.Select(x => x != null ? x.ToString() : "<Null>"))); if (_cacheManager.IsAdd(key)) { args.SetReturnValue(_cacheManager.Get <object>(key)); } base.OnInvoke(args); _cacheManager.Add(key, args.ReturnValue, _cacheByMinute); }