Example #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>());
                    }
                }
            }
        }
Example #2
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            protected override IDisposable CreateTemplateScope(MethodInfo method)
            {
                var parameterTypes    = method.GetParameters().Select(p => p.ParameterType).ToArray();
                var templateTypePairs = new Type[2 * (1 + parameterTypes.Length)];

                templateTypePairs[0] = typeof(TypeTemplate.TReturn);
                templateTypePairs[1] = method.ReturnType;

                TypeTemplate.BuildArgumentsTypePairs(parameterTypes, templateTypePairs, arrayStartIndex: 2);
                return(TypeTemplate.CreateScope(templateTypePairs));
            }
Example #3
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            protected override IDisposable CreateTemplateScope(PropertyInfo property)
            {
                var parameterTypes    = property.GetIndexParameters().Select(p => p.ParameterType).ToArray();
                var templateTypePairs = new Type[2 * (1 + parameterTypes.Length)];

                templateTypePairs[0] = typeof(TypeTemplate.TProperty);
                templateTypePairs[1] = property.PropertyType;

                if (parameterTypes.Length > 0)
                {
                    TypeTemplate.BuildArgumentsTypePairs(parameterTypes, templateTypePairs, arrayStartIndex: 2);
                }

                return(TypeTemplate.CreateScope(templateTypePairs));
            }
Example #4
0
        //-----------------------------------------------------------------------------------------------------------------------------------------------------

        public IDisposable CreateTypeTemplateScope()
        {
            var typePairCount =
                1 +                                                                                        // TBase
                (m_PrimaryInterface != null ? 1 : 0) +                                                     // TPrimary
                (m_SecondaryInterfacesArray != null ? Math.Min(m_SecondaryInterfacesArray.Length, 2) : 0); // TSecondary1, TSecondary2

            var typePairs = new Type[typePairCount * 2];
            var index     = 0;

            typePairs[index++] = typeof(TypeTemplate.TBase);
            typePairs[index++] = m_BaseType;

            if (m_PrimaryInterface != null)
            {
                typePairs[index++] = typeof(TypeTemplate.TPrimary);
                typePairs[index++] = m_PrimaryInterface;
            }

            if (m_SecondaryInterfacesArray != null)
            {
                if (m_SecondaryInterfacesArray.Length >= 1)
                {
                    typePairs[index++] = typeof(TypeTemplate.TSecondary1);
                    typePairs[index++] = m_SecondaryInterfacesArray[0];
                }

                if (m_SecondaryInterfacesArray.Length >= 2)
                {
                    typePairs[index++] = typeof(TypeTemplate.TSecondary2);
                    typePairs[index++] = m_SecondaryInterfacesArray[1];
                }
            }

            return(TypeTemplate.CreateScope(typePairs));
        }
Example #5
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            protected override IDisposable CreateTemplateScope(FieldInfo field)
            {
                return(TypeTemplate.CreateScope <TypeTemplate.TField>(field.FieldType));
            }
Example #6
0
            //-------------------------------------------------------------------------------------------------------------------------------------------------

            protected override IDisposable CreateTemplateScope(EventInfo @event)
            {
                return(TypeTemplate.CreateScope <TypeTemplate.TEventHandler>(@event.EventHandlerType));
            }