Example #1
0
        private static AdviceParameterFlag Validate(this ParameterInfo info, AdviceParameterFlag flag)
        {
            var typeFullName = info.ParameterType.FullName;

            if (typeFullName.Equals(MethodExecutionContextTypeName))
            {
                if (!flag.Contains(AdviceParameterFlag.Context))
                {
                    throw new ArgumentException($"Parameter type {typeFullName} is not allowed for this advice");
                }

                return(AdviceParameterFlag.Context);
            }

            if (typeFullName.Equals(MethodExecutionTypeName))
            {
                if (!flag.Contains(AdviceParameterFlag.Execution))
                {
                    throw new ArgumentException($"Parameter type {typeFullName} is not allowed for this advice");
                }

                return(AdviceParameterFlag.Execution);
            }

            if (typeFullName.Equals(ExceptionTypeName))
            {
                if (!flag.Contains(AdviceParameterFlag.Exception))
                {
                    throw new ArgumentException($"Parameter type {typeFullName} is not allowed for this advice");
                }

                return(AdviceParameterFlag.Exception);
            }

            if (typeFullName.Equals(ReturnTypeName))
            {
                if (!flag.Contains(AdviceParameterFlag.Return))
                {
                    throw new ArgumentException($"Parameter type {typeFullName} is not allowed for this advice");
                }

                return(AdviceParameterFlag.Return);
            }

            if (typeFullName.Equals(BooTypeName))
            {
                if (!flag.Contains(AdviceParameterFlag.HasException))
                {
                    throw new ArgumentException($"Parameter type {typeFullName} is not allowed for this advice");
                }

                return(AdviceParameterFlag.HasException);
            }

            throw new ArgumentException($"Parameter type {typeFullName} is not allowed");
        }