Example #1
0
 public DynamicLoader(ISourceLocationProvider/*?*/ sourceLocationProvider, ILocalScopeProvider/*?*/ localScopeProvider)
 {
     this.sourceLocationProvider = sourceLocationProvider;
       this.localScopeProvider = localScopeProvider;
       this.emitter = new Emitter(this, sourceLocationProvider, localScopeProvider);
       this.initializingTraverser = new MetadataTraverser() { PostorderVisitor = this.emitter, TraverseIntoMethodBodies = true };
       this.typeBuilderAllocator = new TypeBuilderAllocater(this);
       this.typeCreator = new TypeCreator(this);
       this.memberBuilderAllocator = new MemberBuilderAllocator(this);
       this.mapper = new ReflectionMapper();
       this.builderMap = new Dictionary<object, object>();
 }
Example #2
0
		void EmitAttributes(TypeCreator knownTypes)
		{
			AttributeEmitVisitor visitor = new AttributeEmitVisitor(this, knownTypes);
			foreach (Module module in CompileUnit.Modules)
				module.Accept(visitor);
		}
Example #3
0
		void EmitFieldAttributes(TypeMember node, TypeCreator knownTypes)
		{
			FieldBuilder builder = GetFieldBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
Example #4
0
		void EmitTypeAttributes(TypeDefinition node, TypeCreator knownTypes)
		{
			TypeBuilder builder = GetTypeBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
Example #5
0
		void EmitMethodAttributes(Method node, TypeCreator knownTypes)
		{
			MethodBuilder builder = GetMethodBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
Example #6
0
		void EmitConstructorAttributes(Constructor node, TypeCreator knownTypes)
		{
			ConstructorBuilder builder = (ConstructorBuilder)GetBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
Example #7
0
		void EmitEventAttributes(Event node, TypeCreator knownTypes)
		{
			EventBuilder builder = (EventBuilder)GetBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
Example #8
0
		void EmitPropertyAttributes(Property node, TypeCreator knownTypes)
		{
			PropertyBuilder builder = GetPropertyBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
Example #9
0
			public AttributeEmitVisitor(EmitAssembly emitter, TypeCreator knownTypes)
			{
				this._emitter = emitter;
				this._knownTypes = knownTypes;
			}
Example #10
0
		void EmitAttributes(INodeWithAttributes node, CustomAttributeSetter setCustomAttribute, TypeCreator knownTypes)
		{
			foreach (Attribute attribute in node.Attributes)
				knownTypes.CreateAttributeTypes(attribute);
			foreach (Attribute attribute in node.Attributes)
				setCustomAttribute(GetCustomAttributeBuilder(attribute));
		}
Example #11
0
		void DefineTypes()
		{
			if (CompileUnit.Modules.Count == 0)
				return;

			var types = CollectTypes();
			foreach (var type in types)
				DefineType(type);

			foreach (var type in types)
			{
				DefineGenericParameters(type);
				DefineTypeMembers(type);
			}

			foreach (var module in CompileUnit.Modules)
				OnModule(module);

			var typeCreator = new TypeCreator(this, types);
			// TODO: we might need to create enumerations that appear in attributes before emitting the attributes.
			EmitAttributes(typeCreator);
			typeCreator.Run();
		}
        public void Can_Create_Types_In_A_Non_Xaf_Context()
        {
            new PersistentClassInfo(Session.DefaultSession){Name = "Test"}.Save();
            var typeCreator =
                new TypeCreator(
                    new TypesInfo(new List<Type> {
                                                     typeof (PersistentClassInfo),
                                                     typeof (ExtendedCollectionMemberInfo),
                                                     typeof (ExtendedReferenceMemberInfo),
                                                     typeof (ExtendedCoreTypeMemberInfo),
                                                     typeof (InterfaceInfo)
                                                 }), new UnitOfWork(Session.DefaultSession.DataLayer));

            Type dynamicModule = typeCreator.GetDynamicModule();

            Assert.IsNotNull(dynamicModule);
            Assert.IsNotNull(dynamicModule.Assembly.GetTypes().Where(type => type.Name=="Test").FirstOrDefault());
        }
Example #13
0
        protected override void NotifyBeginType()
        {
            var creator = new TypeCreator(this);

            if (_pendingByRef > 0)
            {
                _pendingByRef--;
                creator.ByRef();
            }

            _creators.Push(creator);
        }
Example #14
0
        // Convenience...
        protected void BindImplementationToSpecificService(Container container, Type implementationType, Type serviceType, string key)
        {
            if (serviceType.IsGenericTypeDefinition)
            {
                var unboundGeneric = new UnboundGeneric(serviceType, implementationType, container, this.RegistrationFactory);
                container.AddUnboundGeneric(new TypeKey(serviceType.TypeHandle, key), unboundGeneric);
            }
            else
            {
                var creator = new TypeCreator(implementationType, container);
                var registration = this.CreateRegistration(container, creator);

                container.AddRegistration(new TypeKey(serviceType.TypeHandle, key ?? creator.AttributeKey), registration);
            }
        }
Example #15
0
		void EmitParameterAttributes(ParameterDeclaration node, TypeCreator knownTypes)
		{
			ParameterBuilder builder = (ParameterBuilder)GetBuilder(node);
			EmitAttributes(node, builder.SetCustomAttribute, knownTypes);
		}
Example #16
0
        protected void BindImplementationToServices(Container container, Type implementationType)
        {
            if (this.ServiceTypes.Count > 1)
            {
                var firstGenericType = this.ServiceTypes.FirstOrDefault(x => x.Type.IsGenericTypeDefinition);

                if (firstGenericType != null)
                    throw new StyletIoCRegistrationException(String.Format("Cannot create a multiple-service binding with an unbound generic type {0}", firstGenericType.Type.GetDescription()));

                var creator = new TypeCreator(implementationType, container);
                var registration = this.CreateRegistration(container, creator);

                foreach (var serviceType in this.ServiceTypes)
                {
                    container.AddRegistration(new TypeKey(serviceType.Type.TypeHandle, serviceType.Key ?? creator.AttributeKey), registration);
                }
            }
            else
            {
                this.BindImplementationToSpecificService(container, implementationType, this.ServiceTypes[0].Type, this.ServiceTypes[0].Key);
            }
        }
Example #17
0
        public CreateCommand(TypeCreator typeCreator)
        {
            Trace.Assert(typeCreator != null);

              this.typeCreator = typeCreator;
        }