Beispiel #1
0
        public CacheMethod(MethodInfo method, CacheOperation operation)
        {
            Method    = method ?? throw new ArgumentNullException(nameof(method));
            Operation = operation;

            var returnType = method.ReturnType;

            if (returnType.IsGenericType)
            {
                returnType = returnType.GetGenericTypeDefinition();
            }

            if (typeof(Task) == method.ReturnType ||
                typeof(ValueTask) == method.ReturnType)
            {
                AsyncType = returnType;
                ValueType = typeof(void);
            }
            else if (typeof(Task <>) == returnType ||
                     typeof(ValueTask <>) == returnType)
            {
                AsyncType = returnType;
                ValueType = method.ReturnType.GetGenericArguments()[0];
            }
            else
            {
                ValueType = method.ReturnType;
            }

            WarpedValue = ValueType.IsGenericType && ValueType.GetGenericTypeDefinition() == typeof(ICacheResult <>);
        }
Beispiel #2
0
        public CacheMethod(MethodInfo method, CacheOperation operation)
        {
            Method    = method ?? throw new ArgumentNullException(nameof(method));
            Operation = operation;
#if BuildTask
            var returnType = method.ReturnType;
            if (returnType.IsGenericInstance)
            {
                returnType = returnType.GetElementType();
            }

            if (method.ReturnType.IsType <Task>() ||
                method.ReturnType.IsType <ValueTask>())
            {
                AsyncType = returnType;
                ValueType = CacheTypeResolver.Void;
            }
            else if (returnType.IsType(typeof(Task <>)) ||
                     returnType.IsType(typeof(ValueTask <>)))
            {
                AsyncType = returnType;
                ValueType = ((GenericInstanceType)method.ReturnType).GenericArguments[0];
            }
            else
            {
                ValueType = method.ReturnType;
            }

            WarpedValue = ValueType.IsGenericInstance && ValueType.GetElementType().IsType("NetCache.ICacheResult`1, NetCache.Core");
#else
            var returnType = method.ReturnType;
            if (returnType.IsGenericType)
            {
                returnType = returnType.GetGenericTypeDefinition();
            }

            if (typeof(Task) == method.ReturnType ||
                typeof(ValueTask) == method.ReturnType)
            {
                AsyncType = returnType;
                ValueType = typeof(void);
            }
            else if (typeof(Task <>) == returnType ||
                     typeof(ValueTask <>) == returnType)
            {
                AsyncType = returnType;
                ValueType = method.ReturnType.GetGenericArguments()[0];
            }
            else
            {
                ValueType = method.ReturnType;
            }

            WarpedValue = ValueType.IsGenericType && ValueType.GetGenericTypeDefinition() == typeof(ICacheResult <>);
#endif
        }