Ejemplo n.º 1
0
        public void DefineTypeFacets()
        {
            EnsureState(2);

            if (_mutableType.BaseType != null)
            {
                _context.TypeBuilder.SetParent(_mutableType.BaseType);
            }

            if (_mutableType.MutableTypeInitializer != null)
            {
                _memberEmitter.AddConstructor(_context, _mutableType.MutableTypeInitializer);
            }

            // Creation of initialization members must happen before interfaces, fields or methods are added.
            var initializationMembers = _initializationBuilder.CreateInitializationMembers(_mutableType);
            var initializationMethod  = initializationMembers != null ? initializationMembers.Item2 : null;

            _proxySerializationEnabler.MakeSerializable(_mutableType, initializationMethod);

            foreach (var attribute in _mutableType.AddedCustomAttributes)
            {
                _context.TypeBuilder.SetCustomAttribute(attribute);
            }
            foreach (var ifc in _mutableType.AddedInterfaces)
            {
                _context.TypeBuilder.AddInterfaceImplementation(ifc);
            }
            foreach (var field in _mutableType.AddedFields)
            {
                _memberEmitter.AddField(_context, field);
            }
            foreach (var ctor in _mutableType.AddedConstructors)
            {
                WireAndAddConstructor(_memberEmitter, _context, ctor, initializationMembers);
            }
            foreach (var method in _mutableType.AddedMethods)
            {
                _memberEmitter.AddMethod(_context, method);
            }
            // Note that accessor methods must be added before their associated properties and events.
            foreach (var property in _mutableType.AddedProperties)
            {
                _memberEmitter.AddProperty(_context, property);
            }
            foreach (var evt in _mutableType.AddedEvents)
            {
                _memberEmitter.AddEvent(_context, evt);
            }
        }
Ejemplo n.º 2
0
 private void WireAndAddConstructor(
     IMemberEmitter member, CodeGenerationContext context, MutableConstructorInfo constructor, Tuple <FieldInfo, MethodInfo> initializationMembers)
 {
     _initializationBuilder.WireConstructorWithInitialization(constructor, initializationMembers, _proxySerializationEnabler);
     member.AddConstructor(context, constructor);
 }