diff --git a/samples/src/Universal/Aspects.Universal.csproj b/samples/src/Universal/Aspects.Universal.csproj index c78c8f95..69c996b1 100644 --- a/samples/src/Universal/Aspects.Universal.csproj +++ b/samples/src/Universal/Aspects.Universal.csproj @@ -1,13 +1,19 @@ - + - 1.0.1 + 1.0.2 netstandard2.0 aspect proxy wrapper universal - This package provides simple universal method wrrapper aspect. + This package provides simple universal method wrapper aspect. https://github.com/pamidur/aspect-injector/tree/master/samples/src/Universal + 10 + enable + + + + \ No newline at end of file diff --git a/samples/src/Universal/Aspects/BaseUniversalWrapperAspect.cs b/samples/src/Universal/Aspects/BaseUniversalWrapperAspect.cs index 0cd38378..1696f53a 100644 --- a/samples/src/Universal/Aspects/BaseUniversalWrapperAspect.cs +++ b/samples/src/Universal/Aspects/BaseUniversalWrapperAspect.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; @@ -19,15 +19,15 @@ public abstract class BaseUniversalWrapperAspect private static readonly ConcurrentDictionary<(MethodBase, Type), Lazy> _delegateCache = new ConcurrentDictionary<(MethodBase, Type), Lazy>(); private static readonly MethodInfo _asyncGenericHandler = - typeof(BaseUniversalWrapperAttribute).GetMethod(nameof(BaseUniversalWrapperAttribute.WrapAsync), BindingFlags.NonPublic | BindingFlags.Instance); + typeof(BaseUniversalWrapperAttribute).GetMethod(nameof(BaseUniversalWrapperAttribute.WrapAsync), BindingFlags.NonPublic | BindingFlags.Instance)!; private static readonly MethodInfo _syncGenericHandler = - typeof(BaseUniversalWrapperAttribute).GetMethod(nameof(BaseUniversalWrapperAttribute.WrapSync), BindingFlags.NonPublic | BindingFlags.Instance); + typeof(BaseUniversalWrapperAttribute).GetMethod(nameof(BaseUniversalWrapperAttribute.WrapSync), BindingFlags.NonPublic | BindingFlags.Instance)!; - private static readonly Type _voidTaskResult = Type.GetType("System.Threading.Tasks.VoidTaskResult"); + private static readonly Type _voidTaskResult = Type.GetType("System.Threading.Tasks.VoidTaskResult")!; protected object BaseHandle( - object instance, + object? instance, Type type, MethodBase method, Func target, @@ -53,7 +53,7 @@ protected object BaseHandle( return handler(target, args, eventArgs); } - private Handler CreateMethodHandler(Type returnType, IReadOnlyList wrappers) + private static Handler CreateMethodHandler(Type returnType, IReadOnlyList wrappers) { var targetParam = Expression.Parameter(typeof(Func), "orig"); var eventArgsParam = Expression.Parameter(typeof(AspectEventArgs), "event"); @@ -75,8 +75,8 @@ private Handler CreateMethodHandler(Type returnType, IReadOnlyList(Expression.Convert(Expression.Invoke(next, orig_args), typeof(object)), targetParam, orig_args, eventArgsParam); + var originalArgs = Expression.Parameter(typeof(object[]), "orig_args"); + var handler = Expression.Lambda(Expression.Convert(Expression.Invoke(next, originalArgs), typeof(object)), targetParam, originalArgs, eventArgsParam); var handlerCompiled = handler.Compile(); return handlerCompiled; } - private Handler GetMethodHandler(MethodBase method, Type returnType, IReadOnlyList wrappers) + private static Handler GetMethodHandler(MethodBase method, Type returnType, IReadOnlyList wrappers) { var lazyHandler = _delegateCache.GetOrAdd((method, returnType), _ => new Lazy(() => CreateMethodHandler(returnType, wrappers))); return lazyHandler.Value; diff --git a/samples/src/Universal/Aspects/MethodWrapperAspect.cs b/samples/src/Universal/Aspects/MethodWrapperAspect.cs index f0e7edd9..398265dc 100644 --- a/samples/src/Universal/Aspects/MethodWrapperAspect.cs +++ b/samples/src/Universal/Aspects/MethodWrapperAspect.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using AspectInjector.Broker; @@ -9,7 +9,7 @@ public class MethodWrapperAspect : BaseUniversalWrapperAspect { [Advice(Kind.Around, Targets = Target.Method)] public object Handle( - [Argument(Source.Instance)] object instance, + [Argument(Source.Instance)] object? instance, [Argument(Source.Type)] Type type, [Argument(Source.Metadata)] MethodBase method, [Argument(Source.Target)] Func target, @@ -21,4 +21,4 @@ public object Handle( return BaseHandle(instance, type, method, target, name, args, returnType, triggers); } } -} \ No newline at end of file +} diff --git a/samples/src/Universal/Aspects/PrivateMethodWrapperAspect.cs b/samples/src/Universal/Aspects/PrivateMethodWrapperAspect.cs index afcc498f..9e0e3eff 100644 --- a/samples/src/Universal/Aspects/PrivateMethodWrapperAspect.cs +++ b/samples/src/Universal/Aspects/PrivateMethodWrapperAspect.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using AspectInjector.Broker; @@ -9,7 +9,7 @@ public class PrivateMethodWrapperAspect : BaseUniversalWrapperAspect { [Advice(Kind.Around, Targets = Target.Private | Target.Method)] public object Handle( - [Argument(Source.Instance)] object instance, + [Argument(Source.Instance)] object? instance, [Argument(Source.Type)] Type type, [Argument(Source.Metadata)] MethodBase method, [Argument(Source.Target)] Func target, @@ -21,4 +21,4 @@ public object Handle( return BaseHandle(instance, type, method, target, name, args, returnType, triggers); } } -} \ No newline at end of file +} diff --git a/samples/src/Universal/Aspects/PublicMethodWrapperAspect.cs b/samples/src/Universal/Aspects/PublicMethodWrapperAspect.cs index 393ea184..1ef1629a 100644 --- a/samples/src/Universal/Aspects/PublicMethodWrapperAspect.cs +++ b/samples/src/Universal/Aspects/PublicMethodWrapperAspect.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using AspectInjector.Broker; @@ -9,7 +9,7 @@ public class PublicMethodWrapperAspect : BaseUniversalWrapperAspect { [Advice(Kind.Around, Targets = Target.Public | Target.Method)] public object Handle( - [Argument(Source.Instance)] object instance, + [Argument(Source.Instance)] object? instance, [Argument(Source.Type)] Type type, [Argument(Source.Metadata)] MethodBase method, [Argument(Source.Target)] Func target, @@ -21,4 +21,4 @@ public object Handle( return BaseHandle(instance, type, method, target, name, args, returnType, triggers); } } -} \ No newline at end of file +} diff --git a/samples/src/Universal/Aspects/PublicWrapperAspect.cs b/samples/src/Universal/Aspects/PublicWrapperAspect.cs index a9a42f8f..bd6d9120 100644 --- a/samples/src/Universal/Aspects/PublicWrapperAspect.cs +++ b/samples/src/Universal/Aspects/PublicWrapperAspect.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Reflection; using AspectInjector.Broker; @@ -9,7 +9,7 @@ public class PublicWrapperAspect : BaseUniversalWrapperAspect { [Advice(Kind.Around, Targets = Target.Public | Target.Any)] public object Handle( - [Argument(Source.Instance)] object instance, + [Argument(Source.Instance)] object? instance, [Argument(Source.Type)] Type type, [Argument(Source.Metadata)] MethodBase method, [Argument(Source.Target)] Func target, @@ -21,4 +21,4 @@ public object Handle( return BaseHandle(instance, type, method, target, name, args, returnType, triggers); } } -} \ No newline at end of file +} diff --git a/samples/src/Universal/Events/AspectEventArgs.cs b/samples/src/Universal/Events/AspectEventArgs.cs index d58e9f72..cc24b454 100644 --- a/samples/src/Universal/Events/AspectEventArgs.cs +++ b/samples/src/Universal/Events/AspectEventArgs.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Reflection; @@ -6,12 +6,12 @@ namespace Aspects.Universal.Events { public class AspectEventArgs : EventArgs { - public object Instance { get; internal set; } - public Type Type { get; internal set; } - public MethodBase Method { get; internal set; } - public string Name { get; internal set; } - public IReadOnlyList Args { get; internal set; } - public Type ReturnType { get; internal set; } - public Attribute[] Triggers { get; internal set; } + public object? Instance { get; internal set; } + public Type Type { get; internal set; } = null!; + public MethodBase Method { get; internal set; } = null!; + public string Name { get; internal set; } = null!; + public IReadOnlyList Args { get; internal set; } = null!; + public Type ReturnType { get; internal set; } = null!; + public Attribute[] Triggers { get; internal set; } = null!; } -} \ No newline at end of file +}