private static void CreateMapPack( Type targetType, SerializerEmitter emiter, CollectionTraits traits ) { var il = emiter.GetPackToMethodILGenerator(); var localHolder = new LocalVariableHolder( il ); try { /* * int count = ((ICollection<KeyValuePair<string, DateTime>>)dictionary).Count; * packer.PackMapHeader(count); * foreach (KeyValuePair<string, DateTime> current in dictionary) * { * this._serializer0.PackTo(packer, current.Key); * this._serializer1.PackTo(packer, current.Value); * } */ var collection = localHolder.GetSerializingCollection( targetType ); var item = localHolder.GetSerializingCollectionItem( traits.ElementType ); var keyProperty = traits.ElementType.GetProperty( "Key" ); var valueProperty = traits.ElementType.GetProperty( "Value" ); // This instruction is always ldarg, not to be ldarga. il.EmitAnyLdarg( 2 ); il.EmitAnyStloc( collection ); var count = localHolder.PackingCollectionCount; EmitLoadTarget( targetType, il, collection ); il.EmitGetProperty( traits.CountProperty ); il.EmitAnyStloc( count ); il.EmitAnyLdarg( 1 ); il.EmitAnyLdloc( count ); il.EmitAnyCall( Metadata._Packer.PackMapHeader ); il.EmitPop(); Emittion.EmitForEach( il, traits, collection, ( il0, getCurrentEmitter ) => { if ( traits.ElementType.IsGenericType ) { Contract.Assert( traits.ElementType.GetGenericTypeDefinition() == typeof( KeyValuePair<,> ) ); getCurrentEmitter(); il0.EmitAnyStloc( item ); Emittion.EmitSerializeValue( emiter, il0, 1, traits.ElementType.GetGenericArguments()[ 0 ], null, NilImplication.MemberDefault, il1 => { il1.EmitAnyLdloca( item ); il1.EmitGetProperty( keyProperty ); }, localHolder ); Emittion.EmitSerializeValue( emiter, il0, 1, traits.ElementType.GetGenericArguments()[ 1 ], null, NilImplication.MemberDefault, il1 => { il1.EmitAnyLdloca( item ); il1.EmitGetProperty( valueProperty ); }, localHolder ); } else { Contract.Assert( traits.ElementType == typeof( DictionaryEntry ) ); getCurrentEmitter(); il0.EmitAnyStloc( item ); Emittion.EmitSerializeValue( emiter, il0, 1, typeof( MessagePackObject ), null, NilImplication.MemberDefault, il1 => { il0.EmitAnyLdloca( item ); il0.EmitGetProperty( Metadata._DictionaryEntry.Key ); il0.EmitUnbox_Any( typeof( MessagePackObject ) ); }, localHolder ); Emittion.EmitSerializeValue( emiter, il0, 1, typeof( MessagePackObject ), null, NilImplication.MemberDefault, il1 => { il0.EmitAnyLdloca( item ); il0.EmitGetProperty( Metadata._DictionaryEntry.Value ); il0.EmitUnbox_Any( typeof( MessagePackObject ) ); }, localHolder ); } } ); il.EmitRet(); } finally { il.FlushTrace(); } }
private static void CreateMapPack(Type targetType, SerializerEmitter emiter, CollectionTraits traits) { var il = emiter.GetPackToMethodILGenerator(); var localHolder = new LocalVariableHolder(il); try { /* * int count = ((ICollection<KeyValuePair<string, DateTime>>)dictionary).Count; * packer.PackMapHeader(count); * foreach (KeyValuePair<string, DateTime> current in dictionary) * { * this._serializer0.PackTo(packer, current.Key); * this._serializer1.PackTo(packer, current.Value); * } */ var collection = localHolder.GetSerializingCollection(targetType); var item = localHolder.GetSerializingCollectionItem(traits.ElementType); var keyProperty = traits.ElementType.GetProperty("Key"); var valueProperty = traits.ElementType.GetProperty("Value"); // This instruction is always ldarg, not to be ldarga. il.EmitAnyLdarg(2); il.EmitAnyStloc(collection); var count = localHolder.PackingCollectionCount; EmitLoadTarget(targetType, il, collection); il.EmitGetProperty(traits.CountProperty); il.EmitAnyStloc(count); il.EmitAnyLdarg(1); il.EmitAnyLdloc(count); il.EmitAnyCall(Metadata._Packer.PackMapHeader); il.EmitPop(); Emittion.EmitForEach( il, traits, collection, (il0, getCurrentEmitter) => { if (traits.ElementType.IsGenericType) { Contract.Assert(traits.ElementType.GetGenericTypeDefinition() == typeof(KeyValuePair <,>)); getCurrentEmitter(); il0.EmitAnyStloc(item); Emittion.EmitSerializeValue( emiter, il0, 1, traits.ElementType.GetGenericArguments()[0], null, NilImplication.MemberDefault, il1 => { il1.EmitAnyLdloca(item); il1.EmitGetProperty(keyProperty); }, localHolder ); Emittion.EmitSerializeValue( emiter, il0, 1, traits.ElementType.GetGenericArguments()[1], null, NilImplication.MemberDefault, il1 => { il1.EmitAnyLdloca(item); il1.EmitGetProperty(valueProperty); }, localHolder ); } else { Contract.Assert(traits.ElementType == typeof(DictionaryEntry)); getCurrentEmitter(); il0.EmitAnyStloc(item); Emittion.EmitSerializeValue( emiter, il0, 1, typeof(MessagePackObject), null, NilImplication.MemberDefault, il1 => { il0.EmitAnyLdloca(item); il0.EmitGetProperty(Metadata._DictionaryEntry.Key); il0.EmitUnbox_Any(typeof(MessagePackObject)); }, localHolder ); Emittion.EmitSerializeValue( emiter, il0, 1, typeof(MessagePackObject), null, NilImplication.MemberDefault, il1 => { il0.EmitAnyLdloca(item); il0.EmitGetProperty(Metadata._DictionaryEntry.Value); il0.EmitUnbox_Any(typeof(MessagePackObject)); }, localHolder ); } } ); il.EmitRet(); } finally { il.FlushTrace(); } }
private static void CreateMapPack(Type targetType, SerializerEmitter emiter, CollectionTraits traits) { TracingILGenerator packToMethodILGenerator = emiter.GetPackToMethodILGenerator(); LocalVariableHolder localHolder = new LocalVariableHolder(packToMethodILGenerator); try { < > c__DisplayClass20 class3; LocalBuilder serializingCollection = localHolder.GetSerializingCollection(targetType); LocalBuilder item = localHolder.GetSerializingCollectionItem(traits.ElementType); PropertyInfo keyProperty = traits.ElementType.GetProperty("Key"); PropertyInfo valueProperty = traits.ElementType.GetProperty("Value"); packToMethodILGenerator.EmitAnyLdarg(2); packToMethodILGenerator.EmitAnyStloc(serializingCollection); LocalBuilder packingCollectionCount = localHolder.PackingCollectionCount; EmitLoadTarget(targetType, packToMethodILGenerator, serializingCollection); packToMethodILGenerator.EmitGetProperty(traits.CountProperty); packToMethodILGenerator.EmitAnyStloc(packingCollectionCount); packToMethodILGenerator.EmitAnyLdarg(1); packToMethodILGenerator.EmitAnyLdloc(packingCollectionCount); packToMethodILGenerator.EmitAnyCall(_Packer.PackMapHeader); packToMethodILGenerator.EmitPop(); Emittion.EmitForEach(packToMethodILGenerator, traits, serializingCollection, delegate(TracingILGenerator il0, Action getCurrentEmitter) { Action <TracingILGenerator> loadValueEmitter = null; Action <TracingILGenerator> action2 = null; Action <TracingILGenerator> action3 = null; Action <TracingILGenerator> action4 = null; < > c__DisplayClass20 class1 = class3; if (traits.ElementType.IsGenericType) { Contract.Assert(traits.ElementType.GetGenericTypeDefinition() == typeof(KeyValuePair <,>)); getCurrentEmitter(); il0.EmitAnyStloc(item); if (loadValueEmitter == null) { loadValueEmitter = delegate(TracingILGenerator il1) { il1.EmitAnyLdloca(item); il1.EmitGetProperty(keyProperty); }; } Emittion.EmitSerializeValue(emiter, il0, 1, traits.ElementType.GetGenericArguments()[0], null, NilImplication.MemberDefault, loadValueEmitter, localHolder); if (action2 == null) { action2 = delegate(TracingILGenerator il1) { il1.EmitAnyLdloca(item); il1.EmitGetProperty(valueProperty); }; } Emittion.EmitSerializeValue(emiter, il0, 1, traits.ElementType.GetGenericArguments()[1], null, NilImplication.MemberDefault, action2, localHolder); } else { Contract.Assert(traits.ElementType == typeof(DictionaryEntry)); getCurrentEmitter(); il0.EmitAnyStloc(item); if (action3 == null) { action3 = delegate(TracingILGenerator il1) { il0.EmitAnyLdloca(item); il0.EmitGetProperty(_DictionaryEntry.Key); il0.EmitUnbox_Any(typeof(MessagePackObject)); }; } Emittion.EmitSerializeValue(emiter, il0, 1, typeof(MessagePackObject), null, NilImplication.MemberDefault, action3, localHolder); if (action4 == null) { action4 = delegate(TracingILGenerator il1) { il0.EmitAnyLdloca(item); il0.EmitGetProperty(_DictionaryEntry.Value); il0.EmitUnbox_Any(typeof(MessagePackObject)); }; } Emittion.EmitSerializeValue(emiter, il0, 1, typeof(MessagePackObject), null, NilImplication.MemberDefault, action4, localHolder); } });