Пример #1
0
        protected override void CustomizeContext(GeneratorContext context, IKernel kernel,
                                                 ComponentModel model, object[] arguments)
        {
            AspectDefinition aspect = (AspectDefinition)model.ExtendedProperties["aop.aspect"];

            if (aspect == null)
            {
                return;
            }

            MixinDefinitionCollection mixins = aspect.Mixins;

            foreach (MixinDefinition definition in mixins)
            {
                Type mixinType = definition.TypeReference.ResolvedType;

                try
                {
                    context.AddMixinInstance(Activator.CreateInstance(mixinType));
                }
                catch (Exception e)
                {
                    throw new ApplicationException("Could not instantiate mixin " + mixinType.FullName, e);
                }
            }
        }
        private void CheckIncludes(MixinDefinitionCollection includes)
        {
            IDictionary names = new Hashtable();

            foreach (MixinDefinition type in includes)
            {
                AssertNotNull(type, type.TypeReference.ToString(), "Type name must be specified as as 'Typename in AssemblyName' or as a reference to a global type declared");

                if (type.TypeReference.TargetType == TargetTypeEnum.Link)
                {
                    AssertKeyExists(_globalMixins, type, type.TypeReference.LinkRef, "The referenced mixin is not declared in the global mixins section");
                }

                AssertUnique(names, type, type.TypeReference.ToString(), "You shouldn't include the same mixin more than one time");
            }
        }
Пример #3
0
        protected object[] InstantiateMixins(MixinDefinitionCollection mixins)
        {
            object[] instances = new object[mixins.Count];

            for (int i = 0; i < mixins.Count; i++)
            {
                MixinDefinition definition = mixins[i];
                Type            mixinType  = definition.TypeReference.ResolvedType;

                try
                {
                    instances[i] = Activator.CreateInstance(mixinType);
                }
                catch (Exception e)
                {
                    throw new ProxyFactoryException("Could not instantiate mixin " + mixinType.FullName, e);
                }
            }

            return(instances);
        }