private void CreateContextfulObjectConstructor( AssemblyBuilderEmittingContext context, Type baseType, TracingILGenerator il, Func <ILConstruct> packActionListInitializerProvider, Func <ILConstruct> packActionTableInitializerProvider, Func <ILConstruct> unpackActionListInitializerProvider, Func <ILConstruct> unpackActionTableInitializerProvider, #if FEATURE_TAP Func <ILConstruct> packAsyncActionListInitializerProvider, Func <ILConstruct> packAsyncActionTableInitializerProvider, Func <ILConstruct> unpackAsyncActionListInitializerProvider, Func <ILConstruct> unpackAsyncActionTableInitializerProvider, #endif // FEATURE_TAP Func <ILConstruct> memberNamesInitializerProvider, Func <ILConstruct> unpackToInitializerProvider ) { /* * .ctor( SerializationContext context ) * : base( ( context ?? SerializationContext.Default ).CompabilityOptions.PackerCompatibilityOptions ) * { * this._serializer0 = context.GetSerializer<T0>(); * this._serializer1 = context.GetSerializer<T1>(); * this._serializer2 = context.GetSerializer<T2>(); * : * } */ // : base() il.EmitLdarg_0(); il.EmitLdarg_1(); if (this._specification.TargetCollectionTraits.CollectionType == CollectionKind.NotCollection) { il.EmitCallConstructor( baseType.GetRuntimeConstructor(ConstructorParameterTypes) ); } else { il.EmitCall(this._methodTable[MethodName.RestoreSchema]); il.EmitCallConstructor( baseType.GetRuntimeConstructor(CollectionConstructorParameterTypes) ); } // this._serializerN = context.GetSerializer<T>(); foreach (var entry in this._serializers) { var targetType = Type.GetTypeFromHandle(entry.Key.TypeHandle); MethodInfo getMethod = Metadata._SerializationContext.GetSerializer1_Parameter_Method.MakeGenericMethod(targetType); il.EmitLdarg_0(); il.EmitLdarg_1(); if (targetType.GetIsEnum()) { il.EmitLdarg_1(); il.EmitTypeOf(targetType); il.EmitAnyLdc_I4(( int )entry.Key.EnumSerializationMethod); il.EmitCall(Metadata._EnumMessagePackSerializerHelpers.DetermineEnumSerializationMethodMethod); il.EmitBox(typeof(EnumSerializationMethod)); } else if (DateTimeMessagePackSerializerHelpers.IsDateTime(targetType)) { il.EmitLdarg_1(); il.EmitAnyLdc_I4(( int )entry.Key.DateTimeConversionMethod); il.EmitCall(Metadata._DateTimeMessagePackSerializerHelpers.DetermineDateTimeConversionMethodMethod); il.EmitBox(typeof(DateTimeConversionMethod)); } else { if (entry.Key.PolymorphismSchema == null) { il.EmitLdnull(); } else { entry.Value.SchemaProvider(il); } } il.EmitCallvirt(getMethod); il.EmitStfld(entry.Value.Field); } foreach (var entry in this._cachedFieldInfos) { il.EmitLdarg_0(); il.EmitLdtoken(entry.Value.Target); il.EmitLdtoken(entry.Value.Target.DeclaringType); il.EmitCall(Metadata._FieldInfo.GetFieldFromHandle); il.EmitStfld(entry.Value.StorageFieldBuilder); } foreach (var entry in this._cachedMethodBases) { il.EmitLdarg_0(); il.EmitLdtoken(entry.Value.Target); il.EmitLdtoken(entry.Value.Target.DeclaringType); il.EmitCall(Metadata._MethodBase.GetMethodFromHandle); il.EmitStfld(entry.Value.StorageFieldBuilder); } if (packActionListInitializerProvider != null) { packActionListInitializerProvider().Evaluate(il); } #if FEATURE_TAP if (packAsyncActionListInitializerProvider != null) { packAsyncActionListInitializerProvider().Evaluate(il); } #endif // FEATURE_TAP if (packActionTableInitializerProvider != null) { packActionTableInitializerProvider().Evaluate(il); } #if FEATURE_TAP if (packAsyncActionTableInitializerProvider != null) { packAsyncActionTableInitializerProvider().Evaluate(il); } #endif // FEATURE_TAP if (unpackActionListInitializerProvider != null) { unpackActionListInitializerProvider().Evaluate(il); } #if FEATURE_TAP if (unpackAsyncActionListInitializerProvider != null) { unpackAsyncActionListInitializerProvider().Evaluate(il); } #endif // FEATURE_TAP if (unpackActionTableInitializerProvider != null) { unpackActionTableInitializerProvider().Evaluate(il); } #if FEATURE_TAP if (unpackAsyncActionTableInitializerProvider != null) { unpackAsyncActionTableInitializerProvider().Evaluate(il); } #endif // FEATURE_TAP if (memberNamesInitializerProvider != null) { memberNamesInitializerProvider().Evaluate(il); } if (unpackToInitializerProvider != null) { unpackToInitializerProvider().Evaluate(il); } foreach (var cachedDelegateInfo in context.GetCachedDelegateInfos()) { // this for stfld il.EmitLdargThis(); var delegateType = cachedDelegateInfo.BackingField.FieldType.ResolveRuntimeType(); // Declare backing field now. var field = context.GetDeclaredField(cachedDelegateInfo.BackingField.FieldName).ResolveRuntimeField(); if (cachedDelegateInfo.IsThisInstance) { il.EmitLdargThis(); } else { il.EmitLdnull(); } // OK this should not be ldvirtftn because target is private or static. il.EmitLdftn(cachedDelegateInfo.TargetMethod.ResolveRuntimeMethod()); // call extern .ctor(Object, void*) il.EmitNewobj(delegateType.GetConstructors().Single()); il.EmitStfld(field); } il.EmitRet(); }