Ejemplo n.º 1
0
        public void Weave()
        {
            Type weavedType = null;

            methodWeavers.ForEach(methodWeaver => {
                var methodBuilder = methodWeaver.DefineMethod();
                var ilGenerator   = methodBuilder.GetILGenerator();

                methodWeaver.WeaveMethodScope(ilGenerator);
                methodWeaver.WeaveEndMethod(ilGenerator);
            });

            CreateDefaultConstructor();

            try {
                weavedType = typeDefinition.TypeBuilder.CreateType();
            }
            catch (TypeLoadException ex) {
                if (ex.IsPartialWeavingException())
                {
                    var firstInterface = typeDefinition.TypeBuilder.ImplementedInterfaces.First();

                    throw new TypeWeavingException(Resources.CouldNotWeaveTypeException.Fmt(firstInterface.Name), ex);
                }

                throw;
            }

            registry.Register(new TypeMap(typeDefinition.Type, weavedType), mixinsMap, isComposite: true);
        }
Ejemplo n.º 2
0
        public void Register(TypeMap typeMap, ITypeMapCollection dependencies, bool isComposite = false)
        {
            var name = typeMap.Name ?? typeMap.ServiceType.GetNameFromAttribute() ?? typeMap.ConcreteType.GetNameFromAttribute();

            if (name.IsNotNullOrEmpty())
            {
                typeMap = new TypeMap(typeMap.ServiceType, typeMap.ConcreteType, name);
            }

            regisrty.Register(typeMap, dependencies, isComposite);
        }