You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
publicinterfaceIRocket{stringName{get;set;}doubleFuel{get;set;}voidLaunch();}[Intercept(typeof(IRocket))]publicclassRocket:IRocket{[CheckFuel]publicdoubleFuel{get;set;}publicstringName{get;set;}publicvoidLaunch(){System.Console.WriteLine("Launching rocket in 3...2.....1 🚀");}}publicclassCheckFuelAttribute:PropertyInterceptorAttribute{}[InterceptFor(typeof(CheckFuelAttribute))]publicclassCheckFuelInterceptor:PropertyInterceptor{privatereadonlyLoggerlogger;publicCheckFuelInterceptor(Loggerlogger){this.logger=logger;}// PropertyInterceptor class provides OnGet and OnSet methods.// These methods will be called before the actual method.publicoverrideTaskOnSet(IInvocationinvocation,objectvalue){varhasEnoughFuel=(double)value>70d;if(!hasEnoughFuel)thrownewSystem.Exception("Fuel is not enough to launch.");logger.LogInfo($"[CheckFuel] Fuel: %{value}, enough to launch.");returnTask.FromResult(Task.CompletedTask);}}