Beispiel #1
0
 internal IEnumerable <JobFilterAttribute> GetTypeFilterAttributes(bool useCache)
 {
     return(useCache
         ? ReflectedAttributeCache.GetTypeFilterAttributes(Type)
         : GetFilterAttributes(Type.GetTypeInfo()));
 }
Beispiel #2
0
 internal IEnumerable <JobFilterAttribute> GetMethodFilterAttributes(bool useCache)
 {
     return(useCache
         ? ReflectedAttributeCache.GetMethodFilterAttributes(Method)
         : GetFilterAttributes(Method));
 }
Beispiel #3
0
        private static Job FromExpression([NotNull] LambdaExpression methodCall, [CanBeNull] Type explicitType)
        {
            if (methodCall == null)
            {
                throw new ArgumentNullException(nameof(methodCall));
            }

            var callExpression = methodCall.Body as MethodCallExpression;

            if (callExpression == null)
            {
                throw new ArgumentException("Expression body should be of type `MethodCallExpression`", nameof(methodCall));
            }

            var type          = explicitType ?? callExpression.Method.DeclaringType;
            var argumentTypes = callExpression.Method.GetParameters().Select(x => x.ParameterType).ToArray();
            var method        = type.GetNonOpenMatchingMethod(callExpression.Method.Name, argumentTypes);

            if (explicitType == null && callExpression.Object != null)
            {
                // Creating a job that is based on a scope variable. We should infer its
                // type and method based on its value, and not from the expression tree.

                // TODO: BREAKING: Consider removing this special case entirely.
                // People consider that the whole object is serialized, this is not true.

                var objectValue = GetExpressionValue(callExpression.Object);
                if (objectValue == null)
                {
                    throw new InvalidOperationException("Expression object should be not null.");
                }

                // TODO: BREAKING: Consider using `callExpression.Object.Type` expression instead.
                type = objectValue.GetType();

                // If an expression tree is based on interface, we should use its own
                // MethodInfo instance, based on the same method name and parameter types.
                method = type.GetNonOpenMatchingMethod(
                    callExpression.Method.Name,
                    callExpression.Method.GetParameters().Select(x => x.ParameterType).ToArray());
            }

            var queueAttribute = ReflectedAttributeCache.GetMethodQueueAttribute(method) ??
                                 ReflectedAttributeCache.GetTypeQueueAttribute(type);

            if (queueAttribute == null)
            {
                return(new Job(
                           // ReSharper disable once AssignNullToNotNullAttribute
                           type,
                           method,
                           GetExpressionValues(callExpression.Arguments)));
            }

            return(new Job(
                       // ReSharper disable once AssignNullToNotNullAttribute
                       type,
                       method,
                       GetExpressionValues(callExpression.Arguments),
                       queueAttribute.Queue));
        }