Пример #1
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        void IObjectFactoryConvention.Apply(ObjectFactoryContext context)
        {
            if (m_Will.HasFlag(Will.InspectDeclaration))
            {
                OnInspectDeclaration(context);
            }

            if (m_Will.HasFlag(Will.ImplementBaseClass))
            {
                OnImplementBaseClass(context.CreateImplementationWriter <TypeTemplate.TBase>());
            }

            if (m_Will.HasFlag(Will.ImplementPrimaryInterface) &&
                context.TypeKey.PrimaryInterface != null &&
                ShouldImplementInterface(context, context.TypeKey.PrimaryInterface))
            {
                using (TypeTemplate.CreateScope <TypeTemplate.TInterface>(context.TypeKey.PrimaryInterface))
                {
                    OnImplementPrimaryInterface(context.CreateImplementationWriter <TypeTemplate.TInterface>());
                }
            }

            if (m_Will.HasFlag(Will.ImplementAnySecondaryInterface))
            {
                foreach (var secondaryInterface in context.TypeKey.SecondaryInterfaces
                         .Where(t => ShouldImplementInterface(context, t)))
                {
                    using (TypeTemplate.CreateScope <TypeTemplate.TInterface>(secondaryInterface))
                    {
                        OnImplementAnySecondaryInterface(context.CreateImplementationWriter <TypeTemplate.TInterface>());
                    }
                }
            }

            if (m_Will.HasFlag(Will.ImplementAnyInterface))
            {
                foreach (var secondaryInterface in context.TypeKey.GetAllInterfaces()
                         .Where(t => ShouldImplementInterface(context, t)))
                {
                    using (TypeTemplate.CreateScope <TypeTemplate.TInterface>(secondaryInterface))
                    {
                        OnImplementAnyInterface(context.CreateImplementationWriter <TypeTemplate.TInterface>());
                    }
                }
            }

            if (m_Will.HasFlag(Will.ImplementAnyBaseType))
            {
                foreach (var secondaryInterface in context.TypeKey.GetAllAncestorTypes()
                         .Where(t => !t.IsInterface || ShouldImplementInterface(context, t)))
                {
                    using (TypeTemplate.CreateScope <TypeTemplate.TBase>(secondaryInterface))
                    {
                        OnImplementAnyBaseType(context.CreateImplementationWriter <TypeTemplate.TBase>());
                    }
                }
            }
        }
Пример #2
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public void Apply(ObjectFactoryContext context)
        {
            foreach (var convention in m_ContainedConventions)
            {
                if (convention.ShouldApply(context))
                {
                    convention.Apply(context);
                }
            }
        }
Пример #3
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        private IObjectFactoryConvention[] GetConventions(ObjectFactoryContext context)
        {
            if (m_ConventionSingletonInstances != null)
            {
                return(m_ConventionSingletonInstances);
            }
            else
            {
                return(m_TransientConventionFactory(context).ToArray());
            }
        }
Пример #4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected override ClassType DefineNewClass(TypeKey key)
        {
            var context     = new ObjectFactoryContext(this, key);
            var conventions = GetConventions(context);

            foreach (var convention in conventions)
            {
                if (convention.ShouldApply(context))
                {
                    convention.Apply(context);
                }
            }

            if (context.ClassType == null)
            {
                throw new CodeGenerationException("Class type was not created.");
            }

            return(context.ClassType);
        }
Пример #5
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region IObjectFactoryConvention Members

        public bool ShouldApply(ObjectFactoryContext context)
        {
            return(m_ContainedConventions.Any(c => c.ShouldApply(context)));
        }
Пример #6
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected virtual bool ShouldApply(ObjectFactoryContext context)
        {
            return(true);
        }
Пример #7
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        #region IObjectFactoryConvention Members

        bool IObjectFactoryConvention.ShouldApply(ObjectFactoryContext context)
        {
            return(this.ShouldApply(context));
        }
Пример #8
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected virtual void OnInspectDeclaration(ObjectFactoryContext context)
        {
        }
Пример #9
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        protected virtual bool ShouldImplementInterface(ObjectFactoryContext context, Type interfaceType)
        {
            return(true);
        }
Пример #10
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        void IObjectFactoryConvention.Apply(ObjectFactoryContext context)
        {
            context.CreateDecorationWriter(this);
        }