public override bool CompileTimeValidate(MethodBase method)
        {
            var methodInformation = MethodInformation.GetMethodInformation(method);
            var parameters        = method.GetParameters();

            if (!ValidationFlags.HasFlag(ValidationFlags.NonPublic) && !methodInformation.IsPublic)
            {
                return(false);
            }
            if (!ValidationFlags.HasFlag(ValidationFlags.Properties) && methodInformation.IsProperty)
            {
                return(false);
            }
            if (!ValidationFlags.HasFlag(ValidationFlags.Methods) && !methodInformation.IsProperty)
            {
                return(false);
            }

            _parameterNames = parameters.Select(p => p.Name).ToArray();
            _memberName     = methodInformation.Name;
            _isProperty     = methodInformation.IsProperty;

            var argumentsToValidate = parameters.Where(p => p.MayNotBeNull()).ToArray();

            _inputArgumentsToValidate = ValidationFlags.HasFlag(ValidationFlags.Arguments) ? argumentsToValidate.Where(p => !p.IsOut).Select(p => p.Position).ToArray() : new int[0];

            _outputArgumentsToValidate = ValidationFlags.HasFlag(ValidationFlags.OutValues) ? argumentsToValidate.Where(p => p.ParameterType.IsByRef).Select(p => p.Position).ToArray() : new int[0];

            if (!methodInformation.IsConstructor)
            {
                _validateReturnValue = ValidationFlags.HasFlag(ValidationFlags.ReturnValues) &&
                                       methodInformation.ReturnParameter.MayNotBeNull();
            }

            var validationRequired = _validateReturnValue || _inputArgumentsToValidate.Length > 0 || _outputArgumentsToValidate.Length > 0;

            return(validationRequired);
        }
        public override bool CompileTimeValidate(MethodBase method)
        {
            // This method executes as build time. It should return 'true' if the aspect is actually needed.
            // It sets some aspect fields which will be serialized into the assembly, and deserialized at runtime,
            // so we don't need reflection at runtime.

            MethodInformation methodInformation = MethodInformation.GetMethodInformation(method);

            ParameterInfo[] parameters = method.GetParameters();

            // Check that the aspect applies on the current method.
            if (!ValidationFlags.HasFlag(ValidationFlags.NonPublic) && !methodInformation.IsPublic)
            {
                return(false);
            }
            if (!ValidationFlags.HasFlag(ValidationFlags.Properties) && methodInformation.IsProperty)
            {
                return(false);
            }
            if (!ValidationFlags.HasFlag(ValidationFlags.Methods) && !methodInformation.IsProperty)
            {
                return(false);
            }

            // Store pieces information needed at runtime.
            this.parameterNames = parameters.Select(p => p.Name).ToArray();
            this.memberName     = methodInformation.Name;
            this.isProperty     = methodInformation.IsProperty;

            ParameterInfo[] argumentsToValidate = parameters.Where(p => p.MayNotBeNull()).ToArray();

            // Build the list of input arguments that need to be validated.
            if (ValidationFlags.HasFlag(ValidationFlags.Arguments))
            {
                this.inputArgumentsToValidate = argumentsToValidate.Where(p => !p.IsOut).Select(p => p.Position).ToArray();
            }
            else
            {
                this.inputArgumentsToValidate = new int[0];
            }

            // Build the list of output arguments that need to be validated.
            if (ValidationFlags.HasFlag(ValidationFlags.OutValues))
            {
                this.outputArgumentsToValidate = argumentsToValidate.Where(p => p.ParameterType.IsByRef).Select(p => p.Position).ToArray();
            }
            else
            {
                this.outputArgumentsToValidate = new int[0];
            }

            // Determine whether the return value should be validated.
            if (!methodInformation.IsConstructor)
            {
                this.validateReturnValue = ValidationFlags.HasFlag(ValidationFlags.ReturnValues) && methodInformation.ReturnParameter.MayNotBeNull();
            }

            // Finally, determine if the aspect is useful on the aspect.
            bool validationRequired = this.validateReturnValue || this.inputArgumentsToValidate.Length > 0 || this.outputArgumentsToValidate.Length > 0;

            return(validationRequired);
        }