/// <summary>
        /// Initializes a new instance of the <see cref="SerializerEmitter"/> class.
        /// </summary>
        /// <param name="host">The host <see cref="ModuleBuilder"/>.</param>
        /// <param name="specification">The specification of the serializer.</param>
        /// <param name="baseClass">Type of the base class of the serializer.</param>
        /// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param>
        public SerializerEmitter(ModuleBuilder host, SerializerSpecification specification, Type baseClass, bool isDebuggable)
        {
            Contract.Requires(host != null);
            Contract.Requires(specification != null);
            Contract.Requires(baseClass != null);

            Tracer.Emit.TraceEvent(Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName);

            this._methodTable   = new Dictionary <string, MethodBuilder>();
            this._fieldTable    = new Dictionary <string, FieldBuilder>();
            this._specification = specification;
            this._host          = host;
            this._typeBuilder   =
                host.DefineType(
                    specification.SerializerTypeFullName,
                    TypeAttributes.Sealed | TypeAttributes.Public | TypeAttributes.UnicodeClass | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit,
                    baseClass
                    );

#if DEBUG
            Contract.Assert(this._typeBuilder.BaseType != null, "baseType != null");
#endif // DEBUG
            this._isDebuggable = isDebuggable;

#if !NETFX_35 && !NETSTANDARD1_1 && !NETSTANDARD1_3
            if (isDebuggable && SerializerDebugging.DumpEnabled)
            {
                SerializerDebugging.PrepareDump(host.Assembly as AssemblyBuilder);
            }
#endif // !NETFX_35 && !NETSTANDARD1_1 && !NETSTANDARD1_3
        }
Exemple #2
0
        /// <summary>
        ///		Initializes a new instance of the <see cref="ContextBasedSerializerEmitter"/> class.
        /// </summary>
        /// <param name="specification">The specification of the serializer.</param>
        public ContextBasedSerializerEmitter(SerializerSpecification specification)
        {
            Contract.Requires(specification != null);

            this._targetType = specification.TargetType;
            this._traits     = specification.TargetCollectionTraits;
        }
		/// <summary>
		///		Create new <see cref="AssemblyBuilderEmittingContext"/> for specified <see cref="Type"/>.
		/// </summary>
		/// <param name="targetType">The target type of the serializer.</param>
		/// <param name="targetTypeCollectionTraits">The collection traits of <paramref name="targetType"/>.</param>
		/// <param name="serializerBaseClass">The base class of the serializer.</param>
		/// <returns><see cref="AssemblyBuilderEmittingContext"/>.</returns>
		public AssemblyBuilderEmittingContext CreateEmittingContext( Type targetType, CollectionTraits targetTypeCollectionTraits, Type serializerBaseClass )
		{
			string serializerTypeName, serializerTypeNamespace;
			DefaultSerializerNameResolver.ResolveTypeName(
				this._assemblyBuilder == null,
				targetType,
				this._namespace,
				out serializerTypeName,
				out serializerTypeNamespace
			);
			var spec =
				new SerializerSpecification(
					targetType,
					targetTypeCollectionTraits,
					serializerTypeName,
					serializerTypeNamespace
				);

			this._generatedSerializers.Add( spec );

			return
				new AssemblyBuilderEmittingContext(
					this._context,
					targetType,
					targetType.GetIsEnum()
						? new Func<SerializerEmitter>( () => this._generatorManager.CreateEnumEmitter( this._context, spec ) )
						: () => this._generatorManager.CreateObjectEmitter( spec, serializerBaseClass )
				);
		}
        /// <summary>
        /// Initializes a new instance of the <see cref="FieldBasedSerializerEmitter"/> class.
        /// </summary>
        /// <param name="host">The host <see cref="ModuleBuilder"/>.</param>
        /// <param name="specification">The specification of the serializer.</param>
        /// <param name="baseClass">Type of the base class of the serializer.</param>
        /// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param>
        public FieldBasedSerializerEmitter(ModuleBuilder host, SerializerSpecification specification, Type baseClass, bool isDebuggable)
        {
            Contract.Requires(host != null);
            Contract.Requires(specification != null);
            Contract.Requires(baseClass != null);

            Tracer.Emit.TraceEvent(Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName);
            this._typeBuilder =
                host.DefineType(
                    specification.SerializerTypeFullName,
                    TypeAttributes.Sealed | TypeAttributes.Public | TypeAttributes.UnicodeClass | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit,
                    baseClass
                    );

            this._defaultConstructorBuilder = this._typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, Type.EmptyTypes);
            this._contextConstructorBuilder = this._typeBuilder.DefineConstructor(MethodAttributes.Public, CallingConventions.Standard, ConstructorParameterTypes);

            this._traits = specification.TargetCollectionTraits;
            var baseType = this._typeBuilder.BaseType;

#if DEBUG
            Contract.Assert(baseType != null, "baseType != null");
#endif
            this._serializers  = new Dictionary <SerializerFieldKey, SerializerFieldInfo>();
            this._fieldInfos   = new Dictionary <RuntimeFieldHandle, FieldBuilder>();
            this._methodBases  = new Dictionary <RuntimeMethodHandle, FieldBuilder>();
            this._isDebuggable = isDebuggable;

#if !SILVERLIGHT && !NETFX_35
            if (isDebuggable && SerializerDebugging.DumpEnabled)
            {
                SerializerDebugging.PrepareDump(host.Assembly as AssemblyBuilder);
            }
#endif
        }
		/// <summary>
		///		Create new <see cref="AssemblyBuilderEmittingContext"/> for specified <see cref="Type"/>.
		/// </summary>
		/// <param name="targetType">The target type of the serializer.</param>
		/// <param name="targetTypeCollectionTraits">The collection traits of <paramref name="targetType"/>.</param>
		/// <param name="serializerBaseClass">The base class of the serializer.</param>
		/// <returns><see cref="AssemblyBuilderEmittingContext"/>.</returns>
		public AssemblyBuilderEmittingContext CreateEmittingContext( Type targetType, CollectionTraits targetTypeCollectionTraits, Type serializerBaseClass )
		{
			string serializerTypeName, serializerTypeNamespace;
			DefaultSerializerNameResolver.ResolveTypeName(
				this._assemblyBuilder == null,
				targetType,
				typeof( AssemblyBuilderCodeGenerationContext ).Namespace,
				out serializerTypeName,
				out serializerTypeNamespace 
			);
			var spec =
				new SerializerSpecification(
					targetType,
					targetTypeCollectionTraits,
					serializerTypeName,
					serializerTypeNamespace
				);

			this._generatedSerializers.Add( spec );

			return
				new AssemblyBuilderEmittingContext(
					this._context,
					targetType,
					() => this._generatorManager.CreateEmitter( spec, serializerBaseClass, EmitterFlavor.FieldBased ),
					() => this._generatorManager.CreateEnumEmitter( this._context, spec, EmitterFlavor.FieldBased ) 
				);
		}
		/// <summary>
		///		Initializes a new instance of the <see cref="SerializerEmitter"/> class for enum.
		/// </summary>
		/// <param name="context">A <see cref="SerializationContext"/>.</param>
		/// <param name="host">The host <see cref="ModuleBuilder"/>.</param>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param>
		public SerializerEmitter( SerializationContext context, ModuleBuilder host, SerializerSpecification specification, bool isDebuggable )
			: this( host, specification, typeof( EnumMessagePackSerializer<> ).MakeGenericType( specification.TargetType ), isDebuggable )
		{
			Tracer.Emit.TraceEvent( Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName );

			this._defaultEnumSerializationMethod = context.EnumSerializationOptions.SerializationMethod;
		}
Exemple #7
0
        /// <summary>
        ///		Create new <see cref="AssemblyBuilderEmittingContext"/> for specified <see cref="Type"/>.
        /// </summary>
        /// <param name="targetType">The target type of the serializer.</param>
        /// <param name="targetTypeCollectionTraits">The collection traits of <paramref name="targetType"/>.</param>
        /// <param name="serializerBaseClass">The base class of the serializer.</param>
        /// <returns><see cref="AssemblyBuilderEmittingContext"/>.</returns>
        public AssemblyBuilderEmittingContext CreateEmittingContext(Type targetType, CollectionTraits targetTypeCollectionTraits, Type serializerBaseClass)
        {
            string serializerTypeName, serializerTypeNamespace;

            DefaultSerializerNameResolver.ResolveTypeName(
                this._assemblyBuilder == null,
                targetType,
                typeof(AssemblyBuilderCodeGenerationContext).Namespace,
                out serializerTypeName,
                out serializerTypeNamespace
                );
            var spec =
                new SerializerSpecification(
                    targetType,
                    targetTypeCollectionTraits,
                    serializerTypeName,
                    serializerTypeNamespace
                    );

            this._generatedSerializers.Add(spec);

            return
                (new AssemblyBuilderEmittingContext(
                     this._context,
                     targetType,
                     () => this._generatorManager.CreateEmitter(spec, serializerBaseClass, EmitterFlavor.FieldBased),
                     () => this._generatorManager.CreateEnumEmitter(this._context, spec, EmitterFlavor.FieldBased)
                     ));
        }
        protected override AssemblyBuilderEmittingContext CreateCodeGenerationContextForSerializerCreation(SerializationContext context)
        {
            string serializerTypeName, serializerTypeNamespace;

            DefaultSerializerNameResolver.ResolveTypeName(
                true,
                typeof(TObject),
                this.GetType().Namespace,
                out serializerTypeName,
                out serializerTypeNamespace
                );
            var spec =
                new SerializerSpecification(
                    typeof(TObject),
                    CollectionTraitsOfThis,
                    serializerTypeName,
                    serializerTypeNamespace
                    );

            return
                (new AssemblyBuilderEmittingContext(
                     context,
                     typeof(TObject),
                     () => SerializationMethodGeneratorManager.Get().CreateEmitter(spec, BaseClass, EmitterFlavor.FieldBased),
                     () => SerializationMethodGeneratorManager.Get().CreateEnumEmitter(context, spec, EmitterFlavor.FieldBased)
                     ));
        }
        /// <summary>
        ///		Initializes a new instance of the <see cref="SerializerEmitter"/> class for enum.
        /// </summary>
        /// <param name="context">A <see cref="SerializationContext"/>.</param>
        /// <param name="host">The host <see cref="ModuleBuilder"/>.</param>
        /// <param name="specification">The specification of the serializer.</param>
        /// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param>
        public SerializerEmitter(SerializationContext context, ModuleBuilder host, SerializerSpecification specification, bool isDebuggable)
            : this(host, specification, typeof(EnumMessagePackSerializer <>).MakeGenericType(specification.TargetType), isDebuggable)
        {
            Tracer.Emit.TraceEvent(Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName);

            this._defaultEnumSerializationMethod = context.EnumSerializationOptions.SerializationMethod;
        }
		/// <summary>
		/// Initializes a new instance of the <see cref="SerializerEmitter"/> class.
		/// </summary>
		/// <param name="host">The host <see cref="ModuleBuilder"/>.</param>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="baseClass">Type of the base class of the serializer.</param>
		/// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param>
		public SerializerEmitter( ModuleBuilder host, SerializerSpecification specification, Type baseClass, bool isDebuggable )
		{
			Contract.Requires( host != null );
			Contract.Requires( specification != null );
			Contract.Requires( baseClass != null );

			Tracer.Emit.TraceEvent( Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName );

			this._methodTable = new Dictionary<string, MethodBuilder>();
			this._fieldTable = new Dictionary<string, FieldBuilder>();
			this._specification = specification;
			this._host = host;
			this._typeBuilder =
				host.DefineType(
					specification.SerializerTypeFullName,
					TypeAttributes.Sealed | TypeAttributes.Public | TypeAttributes.UnicodeClass | TypeAttributes.AutoLayout | TypeAttributes.BeforeFieldInit,
					baseClass
				);

#if DEBUG
			Contract.Assert( this._typeBuilder.BaseType != null, "baseType != null" );
#endif // DEBUG
			this._isDebuggable = isDebuggable;

#if DEBUG && !NETFX_35 && !NETSTANDARD1_1 && !NETSTANDARD1_3
			if ( isDebuggable && SerializerDebugging.DumpEnabled )
			{
				SerializerDebugging.PrepareDump( host.Assembly as AssemblyBuilder );
			}
#endif // DEBUG && !NETFX_35 && !NETSTANDARD1_1 && !NETSTANDARD1_3
		}
        /// <summary>
        ///		Create new <see cref="AssemblyBuilderEmittingContext"/> for specified <see cref="Type"/>.
        /// </summary>
        /// <param name="targetType">The target type of the serializer.</param>
        /// <param name="targetTypeCollectionTraits">The collection traits of <paramref name="targetType"/>.</param>
        /// <param name="serializerBaseClass">The base class of the serializer.</param>
        /// <returns><see cref="AssemblyBuilderEmittingContext"/>.</returns>
        public AssemblyBuilderEmittingContext CreateEmittingContext(Type targetType, CollectionTraits targetTypeCollectionTraits, Type serializerBaseClass)
        {
            string serializerTypeName, serializerTypeNamespace;

            DefaultSerializerNameResolver.ResolveTypeName(
                this._assemblyBuilder == null,
                targetType,
                this._namespace,
                out serializerTypeName,
                out serializerTypeNamespace
                );
            var spec =
                new SerializerSpecification(
                    targetType,
                    targetTypeCollectionTraits,
                    serializerTypeName,
                    serializerTypeNamespace
                    );

            this._generatedSerializers.Add(spec);

            return
                (new AssemblyBuilderEmittingContext(
                     this._context,
                     targetType,
                     targetType.GetIsEnum()
                                                ? new Func <SerializerEmitter>(() => this._generatorManager.CreateEnumEmitter(this._context, spec))
                                                : () => this._generatorManager.CreateObjectEmitter(spec, serializerBaseClass)
                     ));
        }
        /// <summary>
        ///		Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
        /// </summary>
        /// <param name="specification">The specification of the serializer.</param>
        /// <param name="baseClass">Type of the base class of the serializer.</param>
        /// <param name="emitterFlavor"><see cref="EmitterFlavor"/>.</param>
        /// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
        public SerializerEmitter CreateEmitter(SerializerSpecification specification, Type baseClass, EmitterFlavor emitterFlavor)
        {
            Contract.Requires(specification != null);
            Contract.Requires(baseClass != null);
            Contract.Ensures(Contract.Result <SerializerEmitter>() != null);

            return(this.CreateEmitterCore(specification, baseClass, emitterFlavor));
        }
Exemple #13
0
        /// <summary>
        ///		Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
        /// </summary>
        /// <param name="context">The <see cref="SerializationContext"/>.</param>
        /// <param name="specification">The specification of the serializer.</param>
        /// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
        public SerializerEmitter CreateEnumEmitter(SerializationContext context, SerializerSpecification specification)
        {
            Contract.Requires(context != null);
            Contract.Requires(specification != null);
            Contract.Ensures(Contract.Result <SerializerEmitter>() != null);

            return(new SerializerEmitter(context, this._module, specification, this._isDebuggable));
        }
        /// <summary>
        ///		Creates new <see cref="EnumSerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
        /// </summary>
        /// <param name="context">The <see cref="SerializationContext"/>.</param>
        /// <param name="specification">The specification of the serializer.</param>
        /// <param name="emitterFlavor"><see cref="EmitterFlavor"/>.</param>
        /// <returns>New <see cref="EnumSerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
        public EnumSerializerEmitter CreateEnumEmitter(SerializationContext context, SerializerSpecification specification, EmitterFlavor emitterFlavor)
        {
            Contract.Requires(context != null);
            Contract.Requires(specification != null);
            Contract.Ensures(Contract.Result <EnumSerializerEmitter>() != null);

            return(this.CreateEnumEmitterCore(context, specification, emitterFlavor));
        }
Exemple #15
0
        /// <summary>
        ///		Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
        /// </summary>
        /// <param name="specification">The specification of the serializer.</param>
        /// <param name="baseClass">Type of the base class of the serializer.</param>
        /// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
        public SerializerEmitter CreateObjectEmitter(SerializerSpecification specification, Type baseClass)
        {
            Contract.Requires(specification != null);
            Contract.Requires(baseClass != null);
            Contract.Ensures(Contract.Result <SerializerEmitter>() != null);

            return(new SerializerEmitter(this._module, specification, baseClass, this._isDebuggable));
        }
Exemple #16
0
 public ContextBasedEnumSerializerEmitter(SerializerSpecification specification)
 {
     this._targetType = specification.TargetType;
     // NOTE: first argument is dummy to align with FieldBased(its 0th arg is this reference).
     this._packUnderyingValueToMethod =
         new DynamicMethod("PackUnderyingValue", null, new[] { typeof(SerializationContext), typeof(Packer), this._targetType });
     this._unpackFromUnderlyingValueMethod =
         new DynamicMethod("UnpackFromUnderlyingValue", this._targetType, new[] { typeof(SerializationContext), typeof(MessagePackObject) });
 }
Exemple #17
0
        /// <summary>
        ///		Creates new <see cref="SerializerEmitter" /> which corresponds to the specified <see cref="EmitterFlavor" />.
        /// </summary>
        /// <param name="specification">The specification of the serializer.</param>
        /// <param name="baseClass">Type of the base class of the serializer.</param>
        /// <param name="emitterFlavor"><see cref="EmitterFlavor" />.</param>
        /// <returns>
        ///		New <see cref="SerializerEmitter" /> which corresponds to the specified <see cref="EmitterFlavor" />.
        /// </returns>
        protected override SerializerEmitter CreateEmitterCore(SerializerSpecification specification, Type baseClass, EmitterFlavor emitterFlavor)
        {
#if !WINDOWS_PHONE
            switch (emitterFlavor)
            {
            case EmitterFlavor.FieldBased:
            {
                return(new FieldBasedSerializerEmitter(this._module, specification, baseClass, this._isDebuggable));
            }

            default:
            {
                return(new ContextBasedSerializerEmitter(specification));
            }
            }
#else
            return(new ContextBasedSerializerEmitter(targetType));
#endif
        }
 protected override DynamicMethodEmittingContext CreateCodeGenerationContextForSerializerCreation(SerializationContext context)
 {
     return
         (new DynamicMethodEmittingContext(
              context,
              typeof(TObject),
              () =>
              SerializationMethodGeneratorManager.Get()
              .CreateEmitter(
                  SerializerSpecification.CreateAnonymous(typeof(TObject), CollectionTraitsOfThis),
                  BaseClass,
                  EmitterFlavor.ContextBased
                  ),
              () =>
              SerializationMethodGeneratorManager.Get()
              .CreateEnumEmitter(
                  context,
                  SerializerSpecification.CreateAnonymous(typeof(TObject), CollectionTraitsOfThis),
                  EmitterFlavor.ContextBased
                  )
              ));
 }
		/// <summary>
		///		Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
		/// </summary>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="baseClass">Type of the base class of the serializer.</param>
		/// <param name="emitterFlavor"><see cref="EmitterFlavor"/>.</param>
		/// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
		public SerializerEmitter CreateEmitter( SerializerSpecification specification, Type baseClass, EmitterFlavor emitterFlavor )
		{
			Contract.Requires( specification != null );
			Contract.Requires( baseClass != null );
			Contract.Ensures( Contract.Result<SerializerEmitter>() != null );

			return this.CreateEmitterCore( specification, baseClass, emitterFlavor );
		}
Exemple #20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FieldBasedSerializerEmitter"/> class.
        /// </summary>
        /// <param name="context">A <see cref="SerializationContext"/>.</param>
        /// <param name="host">The host <see cref="ModuleBuilder"/>.</param>
        /// <param name="specification">The specification of the serializer.</param>
        /// <param name="isDebuggable">Set to <c>true</c> when <paramref name="host"/> is debuggable.</param>
        public FieldBasedEnumSerializerEmitter(SerializationContext context, ModuleBuilder host, SerializerSpecification specification, bool isDebuggable)
        {
            Contract.Requires(host != null);
            Contract.Requires(specification != null);

            Tracer.Emit.TraceEvent(Tracer.EventType.DefineType, Tracer.EventId.DefineType, "Create {0}", specification.SerializerTypeFullName);
            this._typeBuilder =
                host.DefineType(
                    specification.SerializerTypeFullName,
                    TypeAttributes.Sealed | TypeAttributes.Public | TypeAttributes.UnicodeClass | TypeAttributes.AutoLayout |
                    TypeAttributes.BeforeFieldInit,
                    typeof(EnumMessagePackSerializer <>).MakeGenericType(specification.TargetType)
                    );

            this._contextConstructorBuilder =
                this._typeBuilder.DefineConstructor(
                    MethodAttributes.Public,
                    CallingConventions.Standard,
                    ContextConstructorParameterTypes
                    );
            this._defaultEnumSerializationMethod = context.EnumSerializationMethod;
            this._contextAndEnumSerializationMethodConstructorBuilder =
                this._typeBuilder.DefineConstructor(
                    MethodAttributes.Public,
                    CallingConventions.Standard,
                    ContextAndEnumSerializationMethodConstructorParameterTypes
                    );

            this._packUnderlyingValueToMethodBuilder =
                this._typeBuilder.DefineMethod(
                    "PackUnderlyingValueTo",
                    MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.HideBySig,
                    CallingConventions.HasThis,
                    typeof(void),
                    new[] { typeof(Packer), specification.TargetType }
                    );

            this._unpackFromUnderlyingValueMethodBuilder =
                this._typeBuilder.DefineMethod(
                    "UnpackFromUnderlyingValue",
                    MethodAttributes.Family | MethodAttributes.Virtual | MethodAttributes.Final | MethodAttributes.HideBySig,
                    CallingConventions.HasThis,
                    specification.TargetType,
                    UnpackFromUnderlyingValueParameterTypes
                    );

            var baseType = this._typeBuilder.BaseType;

#if DEBUG
            Contract.Assert(baseType != null, "baseType != null");
#endif
            this._typeBuilder.DefineMethodOverride(
                this._packUnderlyingValueToMethodBuilder,
                baseType.GetMethod(
                    this._packUnderlyingValueToMethodBuilder.Name,
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                    )
                );
            this._typeBuilder.DefineMethodOverride(
                this._unpackFromUnderlyingValueMethodBuilder,
                baseType.GetMethod(
                    this._unpackFromUnderlyingValueMethodBuilder.Name,
                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic
                    )
                );
            this._isDebuggable = isDebuggable;

#if !SILVERLIGHT && !NETFX_35
            if (isDebuggable && SerializerDebugging.DumpEnabled)
            {
                SerializerDebugging.PrepareDump(host.Assembly as AssemblyBuilder);
            }
#endif
        }
		/// <summary>
		///		Creates new <see cref="EnumSerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
		/// </summary>
		/// <param name="context">The <see cref="SerializationContext"/>.</param>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="emitterFlavor"><see cref="EmitterFlavor"/>.</param>
		/// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
		protected abstract EnumSerializerEmitter CreateEnumEmitterCore( SerializationContext context, SerializerSpecification specification, EmitterFlavor emitterFlavor );
		/// <summary>
		///		Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
		/// </summary>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="baseClass">Type of the base class of the serializer.</param>
		/// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
		public SerializerEmitter CreateObjectEmitter( SerializerSpecification specification, Type baseClass )
		{
			Contract.Requires( specification != null );
			Contract.Requires( baseClass != null );
			Contract.Ensures( Contract.Result<SerializerEmitter>() != null );

			return new SerializerEmitter( this._module, specification, baseClass, this._isDebuggable );
		}
		/// <summary>
		///		Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
		/// </summary>
		/// <param name="context">The <see cref="SerializationContext"/>.</param>
		/// <param name="specification">The specification of the serializer.</param>
		/// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
		public SerializerEmitter CreateEnumEmitter( SerializationContext context, SerializerSpecification specification )
		{
			Contract.Requires( context != null );
			Contract.Requires( specification != null );
			Contract.Ensures( Contract.Result<SerializerEmitter>() != null );

			return new SerializerEmitter( context, this._module, specification, this._isDebuggable );
		}
 /// <summary>
 ///		Creates new <see cref="EnumSerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
 /// </summary>
 /// <param name="context">The <see cref="SerializationContext"/>.</param>
 /// <param name="specification">The specification of the serializer.</param>
 /// <param name="emitterFlavor"><see cref="EmitterFlavor"/>.</param>
 /// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
 protected abstract EnumSerializerEmitter CreateEnumEmitterCore(SerializationContext context, SerializerSpecification specification, EmitterFlavor emitterFlavor);
		/// <summary>
		///		Creates new <see cref="EnumSerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
		/// </summary>
		/// <param name="context">The <see cref="SerializationContext"/>.</param>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="emitterFlavor"><see cref="EmitterFlavor"/>.</param>
		/// <returns>New <see cref="EnumSerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
		public EnumSerializerEmitter CreateEnumEmitter( SerializationContext context, SerializerSpecification specification, EmitterFlavor emitterFlavor )
		{
			Contract.Requires( context != null );
			Contract.Requires( specification != null );
			Contract.Ensures( Contract.Result<EnumSerializerEmitter>() != null );

			return this.CreateEnumEmitterCore( context, specification, emitterFlavor );
		}
		/// <summary>
		///		Creates new <see cref="EnumSerializerEmitter" /> which corresponds to the specified <see cref="EmitterFlavor" />.
		/// </summary>
		/// <param name="context">The <see cref="SerializationContext" />.</param>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="emitterFlavor"><see cref="EmitterFlavor" />.</param>
		/// <returns>
		///		New <see cref="SerializerEmitter" /> which corresponds to the specified <see cref="EmitterFlavor" />.
		/// </returns>
		protected override EnumSerializerEmitter CreateEnumEmitterCore( SerializationContext context, SerializerSpecification specification, EmitterFlavor emitterFlavor )
		{
#if !WINDOWS_PHONE
			switch ( emitterFlavor )
			{
				case EmitterFlavor.FieldBased:
				{
					return new FieldBasedEnumSerializerEmitter( context, this._module, specification, this._isDebuggable );
				}
				default:
				{
					return new ContextBasedEnumSerializerEmitter( specification );
				}
			}
#else
			return new ContextBasedEnumSerializerEmitter( targetType );
#endif
		}
 /// <summary>
 ///		Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
 /// </summary>
 /// <param name="specification">The specification of the serializer.</param>
 /// <param name="baseClass">Type of the base class of the serializer.</param>
 /// <param name="emitterFlavor"><see cref="EmitterFlavor"/>.</param>
 /// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
 protected abstract SerializerEmitter CreateEmitterCore(SerializerSpecification specification, Type baseClass, EmitterFlavor emitterFlavor);
		/// <summary>
		///		Creates new <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.
		/// </summary>
		/// <param name="specification">The specification of the serializer.</param>
		/// <param name="baseClass">Type of the base class of the serializer.</param>
		/// <param name="emitterFlavor"><see cref="EmitterFlavor"/>.</param>
		/// <returns>New <see cref="SerializerEmitter"/> which corresponds to the specified <see cref="EmitterFlavor"/>.</returns>
		protected abstract SerializerEmitter CreateEmitterCore( SerializerSpecification specification, Type baseClass, EmitterFlavor emitterFlavor );