Aspectacular.RequiredAspectAttribute.RequiredAspectAttribute C# (CSharp) Method

RequiredAspectAttribute() public method

Use to ensure certain aspect is used when method is intercepted.
public RequiredAspectAttribute ( Type aspectType, WhenRequiredAspectIsMissing missingAspectOption ) : System
aspectType System.Type
missingAspectOption WhenRequiredAspectIsMissing
return System
        public RequiredAspectAttribute(Type aspectType, WhenRequiredAspectIsMissing missingAspectOption, params object[] constructorArgs)
        {
            if(aspectType == null)
                throw new ArgumentNullException("aspectType");

            if(!aspectType.IsSubclassOf(typeof(Aspect)))
                throw new ArgumentException("aspectType must be a subclass of the Aspect class.");

            this.AspectClassType = aspectType;

            if(missingAspectOption != WhenRequiredAspectIsMissing.DontInstantiate)
            {
                // Need to instantiate missing aspect
                Func<object> rawActivator = aspectType.GetFastActivatorWithEmbeddedArgs(constructorArgs);
                if(rawActivator != null)
                {
                    this.activator = () => (Aspect)rawActivator();
                } else
                {
                    // No activator found
                    string strErrorMsg = "Unable to find {0}({1}) constructor necessary to instantiate required missing aspect {0}."
                        .SmartFormat(aspectType.FormatCSharp(),
                            string.Join(", ", constructorArgs.Select(arg => arg == null ? "[ANY]" : arg.GetType().FormatCSharp()))
                        );

                    throw new ArgumentException(strErrorMsg, "aspectType");
                }
            }

            this.InstantiateIfMissing = missingAspectOption;
        }