/*----------------------------------------------------------------------------------------*/
        /// <summary>
        /// Creates a terminating condition that determines whether the subject is decorated
        /// with an attribute that matches the provided attribute.
        /// </summary>
        /// <typeparam name="T">The type of attribute to look for.</typeparam>
        /// <param name="attribute">The attribute to compare against.</param>
        /// <returns>A condition that terminates the chain.</returns>
        public TerminatingCondition <TRoot, TSubject> HasMatchingAttribute <T>(T attribute)
            where T : Attribute
        {
#if !MONO
            return(Terminate(s => s.HasMatchingAttribute(attribute)));
#else
            return(Terminate(s => ExtensionsForICustomAttributeProvider.HasMatchingAttribute(s, attribute)));
#endif
        }
        /*----------------------------------------------------------------------------------------*/
        /// <summary>
        /// Executed to build the activation plan.
        /// </summary>
        /// <param name="binding">The binding that points at the type whose activation plan is being released.</param>
        /// <param name="type">The type whose activation plan is being manipulated.</param>
        /// <param name="plan">The activation plan that is being manipulated.</param>
        /// <returns>
        /// A value indicating whether to proceed or interrupt the strategy chain.
        /// </returns>
        public override StrategyResult Build(IBinding binding, Type type, IActivationPlan plan)
        {
            EventInfo[] events = type.GetEvents(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (EventInfo evt in events)
            {
#if !MONO
                PublishAttribute[] attributes = evt.GetAllAttributes <PublishAttribute>();
#else
                PublishAttribute[] attributes = ExtensionsForICustomAttributeProvider.GetAllAttributes <PublishAttribute>(evt);
#endif

                foreach (PublishAttribute attribute in attributes)
                {
                    plan.Directives.Add(new PublicationDirective(attribute.Channel, evt));
                }
            }

            MethodInfo[] methods         = type.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
            var          injectorFactory = binding.Components.Get <IInjectorFactory>();

            foreach (MethodInfo method in methods)
            {
#if !MONO
                SubscribeAttribute[] attributes = method.GetAllAttributes <SubscribeAttribute>();
#else
                SubscribeAttribute[] attributes = ExtensionsForICustomAttributeProvider.GetAllAttributes <SubscribeAttribute>(method);
#endif
                foreach (SubscribeAttribute attribute in attributes)
                {
                    IMethodInjector injector = injectorFactory.GetInjector(method);
                    plan.Directives.Add(new SubscriptionDirective(attribute.Channel, injector, attribute.Thread));
                }
            }

            return(StrategyResult.Proceed);
        }
Exemple #3
0
        /// <summary>
        /// Reads whether the target represents an optional dependency.
        /// </summary>
        /// <returns><see langword="True"/> if it is optional; otherwise <see langword="false"/>.</returns>
        protected virtual bool ReadOptionalFromTarget()

        {
            return(ExtensionsForICustomAttributeProvider.HasAttribute(Site, typeof(OptionalAttribute)));
        }
Exemple #4
0
        /// <summary>
        /// Returns a value indicating whether an attribute of the specified type is defined on the target.
        /// </summary>
        /// <param name="attributeType">The type of attribute to search for.</param>
        /// <param name="inherit">Whether to look up the hierarchy chain for inherited custom attributes.</param>
        /// <returns><c>True</c> if such an attribute is defined; otherwise <c>false</c>.</returns>
        public bool IsDefined(Type attributeType, bool inherit)

        {
            return(ExtensionsForICustomAttributeProvider.IsDefined(Site, attributeType, inherit));
        }
Exemple #5
0
        /// <summary>
        /// Returns an array of custom attributes defined on the target.
        /// </summary>
        /// <param name="inherit">Whether to look up the hierarchy chain for inherited custom attributes.</param>
        /// <returns>An array of custom attributes.</returns>
        public IEnumerable <Attribute> GetCustomAttributes(bool inherit)

        {
            return(ExtensionsForICustomAttributeProvider.GetCustomAttributes(Site, (inherit)));
        }
Exemple #6
0
        GetCustomAttributes(Type attributeType, bool inherit)

        {
            return(ExtensionsForICustomAttributeProvider.GetCustomAttributesExtended(Site, attributeType, inherit));
        }