Skip to content

Commit 5fc5562

Browse files
committed
Re-enable Xamarin AOT workaround.
1 parent d66d8e8 commit 5fc5562

File tree

4 files changed

+22
-65
lines changed

4 files changed

+22
-65
lines changed

src/MsgPack/Serialization/CollectionSerializers/CollectionMessagePackSerializerBase`2.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#region -- License Terms --
1+
#region -- License Terms --
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2015-2016 FUJIWARA, Yusuke
5+
// Copyright (C) 2015-2018 FUJIWARA, Yusuke
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -83,7 +83,7 @@ protected CollectionMessagePackSerializerBase( SerializationContext ownerContext
8383
protected internal override void PackToCore( Packer packer, TCollection objectTree )
8484
{
8585
packer.PackArrayHeader( this.GetCount( objectTree ) );
86-
#if ( !UNITY ) || AOT_CHECK
86+
#if ( !UNITY && !AOT ) || AOT_CHECK
8787
var itemSerializer = this.ItemSerializer;
8888
foreach ( var item in objectTree )
8989
{
@@ -121,7 +121,7 @@ protected internal override void PackToCore( Packer packer, TCollection objectTr
121121
protected internal override async Task PackToAsyncCore( Packer packer, TCollection objectTree, CancellationToken cancellationToken )
122122
{
123123
await packer.PackArrayHeaderAsync( this.GetCount( objectTree ), cancellationToken ).ConfigureAwait( false );
124-
#if ( !UNITY ) || AOT_CHECK
124+
#if ( !UNITY && !AOT ) || AOT_CHECK
125125
var itemSerializer = this.ItemSerializer;
126126
foreach ( var item in objectTree )
127127
{
@@ -230,4 +230,4 @@ internal virtual Task<TCollection> InternalUnpackFromAsyncCore( Unpacker unpacke
230230

231231
#endif // FEATURE_TAP
232232
}
233-
}
233+
}

src/MsgPack/Serialization/CollectionSerializers/CollectionMessagePackSerializer`2.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#region -- License Terms --
1+
#region -- License Terms --
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2015-2016 FUJIWARA, Yusuke
5+
// Copyright (C) 2015-2018 FUJIWARA, Yusuke
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -76,7 +76,7 @@ protected CollectionMessagePackSerializer( SerializationContext ownerContext, Po
7676
/// <returns>The count of the <paramref name="collection"/>.</returns>
7777
protected override int GetCount( TCollection collection )
7878
{
79-
#if ( !UNITY ) || AOT_CHECK
79+
#if ( !UNITY && !AOT ) || AOT_CHECK
8080
return collection.Count;
8181
#else
8282
// .constraind call for TCollection.get_Count/TCollection.GetEnumerator() causes AOT error.
@@ -94,7 +94,7 @@ protected override int GetCount( TCollection collection )
9494
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]
9595
protected override void AddItem( TCollection collection, TItem item )
9696
{
97-
#if ( !UNITY ) || AOT_CHECK
97+
#if ( !UNITY && !AOT ) || AOT_CHECK
9898
collection.Add( item );
9999
#else
100100
// .constraind call for TCollection.Add causes AOT error.
@@ -160,4 +160,4 @@ protected override void AddItem( object collection, object item )
160160
}
161161
}
162162
#endif // UNITY
163-
}
163+
}

src/MsgPack/Serialization/CollectionSerializers/DictionaryMessagePackSerializerBase`3.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2015-2016 FUJIWARA, Yusuke
5+
// Copyright (C) 2015-2018 FUJIWARA, Yusuke
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -102,7 +102,7 @@ protected DictionaryMessagePackSerializerBase( SerializationContext ownerContext
102102
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "1", Justification = "Validated by caller in base class" )]
103103
protected internal override void PackToCore( Packer packer, TDictionary objectTree )
104104
{
105-
#if ( !UNITY ) || AOT_CHECK
105+
#if ( !UNITY && !AOT ) || AOT_CHECK
106106
packer.PackMapHeader( this.GetCount( objectTree ) );
107107
foreach ( var item in objectTree )
108108
{
@@ -141,7 +141,7 @@ protected internal override void PackToCore( Packer packer, TDictionary objectTr
141141
/// <seealso cref="P:Capabilities"/>
142142
protected internal override async Task PackToAsyncCore( Packer packer, TDictionary objectTree, CancellationToken cancellationToken )
143143
{
144-
#if ( !UNITY ) || AOT_CHECK
144+
#if ( !UNITY && !AOT ) || AOT_CHECK
145145
await packer.PackMapHeaderAsync( this.GetCount( objectTree ), cancellationToken ).ConfigureAwait( false );
146146
foreach ( var item in objectTree )
147147
{
@@ -187,7 +187,7 @@ protected internal override async Task PackToAsyncCore( Packer packer, TDictiona
187187
/// <typeparamref name="TDictionary"/> is abstract type.
188188
/// </exception>
189189
/// <remarks>
190-
/// This method invokes <see cref="CreateInstance(int)"/>, and then fill deserialized items to resultong collection.
190+
/// This method invokes <see cref="CreateInstance(Int32)"/>, and then fill deserialized items to resultong collection.
191191
/// </remarks>
192192
[System.Diagnostics.CodeAnalysis.SuppressMessage( "Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods", MessageId = "0", Justification = "Validated by caller in base class" )]
193193
protected internal override TDictionary UnpackFromCore( Unpacker unpacker )
@@ -444,4 +444,4 @@ protected virtual void AddItem( TDictionary dictionary, TKey key, TValue value )
444444
throw SerializationExceptions.NewUnpackToIsNotSupported( typeof( TDictionary ), null );
445445
}
446446
}
447-
}
447+
}

src/MsgPack/Serialization/CollectionSerializers/DictionaryMessagePackSerializer`3.cs

Lines changed: 7 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// MessagePack for CLI
44
//
5-
// Copyright (C) 2015-2016 FUJIWARA, Yusuke
5+
// Copyright (C) 2015-2018 FUJIWARA, Yusuke
66
//
77
// Licensed under the Apache License, Version 2.0 (the "License");
88
// you may not use this file except in compliance with the License.
@@ -83,36 +83,15 @@ protected DictionaryMessagePackSerializer( SerializationContext ownerContext, Po
8383
/// <returns>The count of the <paramref name="dictionary"/>.</returns>
8484
protected override int GetCount( TDictionary dictionary )
8585
{
86-
#if !NETSTANDARD2_0
86+
#if !AOT
8787
return dictionary.Count;
88-
#else // NETSTANDARD2_0
89-
if ( SerializerOptions.CanEmit )
90-
{
91-
return this.GetCountCore( dictionary );
92-
}
93-
else
94-
{
95-
return this.GetCountCoreAotSafe( dictionary );
96-
}
97-
#endif // !NETSTANDARD2_0
98-
}
99-
100-
#if NETSTANDARD2_0
101-
102-
private int GetCountCore( TDictionary dictionary )
103-
{
104-
return dictionary.Count;
105-
}
106-
107-
private int GetCountCoreAotSafe( TDictionary dictionary )
108-
{
88+
#else // !AOT
10989
// .constraind call for TDictionary.get_Count/TDictionary.GetEnumerator() causes AOT error.
11090
// So use cast and invoke as normal call (it might cause boxing, but most collection should be reference type).
11191
return ( dictionary as IDictionary<TKey, TValue> ).Count;
92+
#endif // !AOT
11293
}
11394

114-
#endif // NETSTANDARD2_0
115-
11695
/// <summary>
11796
/// Adds the deserialized item to the collection on <typeparamref name="TDictionary"/> specific manner
11897
/// to implement <see cref="DictionaryMessagePackSerializerBase{TDictionary,TKey,TValue}.UnpackToCore(MsgPack.Unpacker,TDictionary)"/>.
@@ -125,36 +104,14 @@ private int GetCountCoreAotSafe( TDictionary dictionary )
125104
/// </exception>
126105
protected override void AddItem( TDictionary dictionary, TKey key, TValue value )
127106
{
128-
#if !NETSTANDARD2_0
107+
#if !AOT
129108
dictionary.Add( key, value );
130-
#else // !NETSTANDARD2_0
131-
if ( SerializerOptions.CanEmit)
132-
{
133-
this.AddItemCore( dictionary, key, value );
134-
}
135-
else
136-
{
137-
this.AddItemCoreAotSafe( dictionary, key, value );
138-
}
139-
#endif // !NETSTANDARD2_0
140-
}
141-
142-
#if NETSTANDARD2_0
143-
144-
private void AddItemCore( TDictionary dictionary, TKey key, TValue value )
145-
{
146-
dictionary.Add( key, value );
147-
}
148-
149-
private void AddItemCoreAotSafe( TDictionary dictionary, TKey key, TValue value )
150-
{
109+
#else // !AOT
151110
// .constraind call for TDictionary.Add causes AOT error.
152111
// So use cast and invoke as normal call (it might cause boxing, but most collection should be reference type).
153112
( dictionary as IDictionary<TKey, TValue> ).Add( key, value );
113+
#endif // !AOT
154114
}
155-
156-
#endif // NETSTANDARD2_0
157-
158115
}
159116

160117
#if UNITY

0 commit comments

Comments
 (0)