예제 #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);
        }