forked from msgpack/msgpack-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoMessagePackSerializerTest.Types.ttinclude
More file actions
513 lines (478 loc) · 24.3 KB
/
AutoMessagePackSerializerTest.Types.ttinclude
File metadata and controls
513 lines (478 loc) · 24.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
<#@ import namespace="System" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Collections.ObjectModel" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Numerics" #>
<#@ import namespace="System.Reflection" #>
<#@ import namespace="System.Runtime.InteropServices.ComTypes" #>
<#@ import namespace="System.Text" #>
<#+
void GenerateTypes()
{
GenerateTypesCore( false );
}
void GenerateTypesForIos()
{
GenerateTypesCore( true );
}
private void GenerateTypesCore( bool forIos )
{
var __fields =
new Tuple<Object, string, string, bool>[]
{
new Tuple<Object, string, string, bool>( typeof( Object ), "NullField", "null", true ),
new Tuple<Object, string, string, bool>( typeof( Boolean ), "TrueField", "true", true ),
new Tuple<Object, string, string, bool>( typeof( Boolean ), "FalseField", "false", true ),
new Tuple<Object, string, string, bool>( typeof( Byte ), "TinyByteField", "1", true ),
new Tuple<Object, string, string, bool>( typeof( Byte ), "ByteField", "0x80", true ),
new Tuple<Object, string, string, bool>( typeof( Byte ), "MaxByteField", "0xff", true ),
new Tuple<Object, string, string, bool>( typeof( UInt16 ), "TinyUInt16Field", "0x100", true ),
new Tuple<Object, string, string, bool>( typeof( UInt16 ), "MaxUInt16Field", "0xffff", true ),
new Tuple<Object, string, string, bool>( typeof( Int32 ), "TinyInt32Field", "0x10000", true ),
new Tuple<Object, string, string, bool>( typeof( Int32 ), "MaxInt32Field", "Int32.MaxValue", true ),
new Tuple<Object, string, string, bool>( typeof( Int32 ), "MinInt32Field", "Int32.MinValue", true ),
new Tuple<Object, string, string, bool>( typeof( Int64 ), "TinyInt64Field", "0x100000000", true ),
new Tuple<Object, string, string, bool>( typeof( Int64 ), "MaxInt64Field", "Int64.MaxValue", true ),
new Tuple<Object, string, string, bool>( typeof( Int64 ), "MinInt64Field", "Int64.MinValue", true ),
new Tuple<Object, string, string, bool>( typeof( DateTime ), String.Empty, "DateTime.UtcNow", true ),
new Tuple<Object, string, string, bool>( typeof( DateTimeOffset ), String.Empty, "DateTimeOffset.UtcNow", true ),
new Tuple<Object, string, string, bool>( typeof( Uri ), String.Empty, "new Uri( \"http://example.com/\" )", true ),
new Tuple<Object, string, string, bool>( typeof( Version ), String.Empty, "new Version( 1, 2, 3, 4 )", true ),
new Tuple<Object, string, string, bool>( typeof( FILETIME ), String.Empty, "ToFileTime( DateTime.UtcNow )", true ),
new Tuple<Object, string, string, bool>( typeof( TimeSpan ), String.Empty, "TimeSpan.FromMilliseconds( 123456789 )", true ),
new Tuple<Object, string, string, bool>( typeof( Guid ), String.Empty, "Guid.NewGuid()", true ),
new Tuple<Object, string, string, bool>( typeof( Char ), String.Empty, "'\u3000'", true ),
new Tuple<Object, string, string, bool>( typeof( Decimal ), String.Empty, "123456789.0987654321m", true ),
new Tuple<Object, string, string, bool>( typeof( BigInteger ), String.Empty, "new BigInteger( UInt64.MaxValue ) + UInt64.MaxValue", true ),
new Tuple<Object, string, string, bool>( typeof( Complex ), String.Empty, "new Complex( 1.3, 2.4 )", true ),
new Tuple<Object, string, string, bool>( typeof( DictionaryEntry ), String.Empty, "new DictionaryEntry( new MessagePackObject( \"Key\" ), new MessagePackObject( \"Value\" ) )", true ),
new Tuple<Object, string, string, bool>( typeof( KeyValuePair<String, DateTimeOffset> ), String.Empty, "new KeyValuePair<String, DateTimeOffset>( \"Key\", DateTimeOffset.UtcNow )", true ),
new Tuple<Object, string, string, bool>( typeof( KeyValuePair<String, Complex> ), String.Empty, "new KeyValuePair<String, Complex>( \"Key\", new Complex( 1.3, 2.4 ) )", true ),
new Tuple<Object, string, string, bool>( typeof( String ), String.Empty, "\"StringValue\"", true ),
new Tuple<Object, string, string, bool>( typeof( Byte[] ), String.Empty, "new Byte[]{ 1, 2, 3, 4 }", true ),
new Tuple<Object, string, string, bool>( typeof( Char[] ), String.Empty, "\"ABCD\".ToCharArray()", true ),
new Tuple<Object, string, string, bool>( typeof( ArraySegment<Byte> ), String.Empty, "new ArraySegment<Byte>( new Byte[]{ 1, 2, 3, 4 } )", true ),
new Tuple<Object, string, string, bool>( typeof( ArraySegment<Int32> ), String.Empty, "new ArraySegment<Int32>( new Int32[]{ 1, 2, 3, 4 } )", true ),
new Tuple<Object, string, string, bool>( typeof( ArraySegment<Decimal> ), String.Empty, "new ArraySegment<Decimal>( new Decimal[]{ 1, 2, 3, 4 } )", true ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( Tuple<,,,> ).FullName, new [] { typeof( Int32 ).FullName, typeof( String ).FullName, "MsgPack.MessagePackObject", typeof( Object ).FullName } ), String.Empty, "new Tuple<Int32, String, MessagePackObject, Object>( 1, \"ABC\", new MessagePackObject( \"abc\" ), new MessagePackObject( \"123\" ) ) ", true ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( "MsgPack.Image", new String[ 0 ] ), String.Empty, "new Image(){ uri = \"http://example.com/logo.png\", title = \"logo\", width = 160, height = 120, size = 13612 }", true ),
new Tuple<Object, string, string, bool>( typeof( List<DateTime> ), String.Empty, "new List<DateTime>(){ DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ), DateTime.UtcNow }", false ),
new Tuple<Object, string, string, bool>( typeof( Dictionary<String, DateTime> ), String.Empty, "new Dictionary<String, DateTime>(){ { \"Yesterday\", DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ) }, { \"Today\", DateTime.UtcNow } }", false ),
new Tuple<Object, string, string, bool>( typeof( Collection<DateTime> ), String.Empty, "new Collection<DateTime>(){ DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ), DateTime.UtcNow }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( "MsgPack.Serialization.StringKeyedCollection`1", new []{ typeof( DateTime ).FullName } ), String.Empty, "new StringKeyedCollection<DateTime>(){ DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ), DateTime.UtcNow }", false ),
new Tuple<Object, string, string, bool>( typeof( ObservableCollection<DateTime> ), String.Empty, "new ObservableCollection<DateTime>(){ DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ), DateTime.UtcNow }", false ),
new Tuple<Object, string, string, bool>( typeof( HashSet<DateTime> ), String.Empty, "new HashSet<DateTime>(){ DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ), DateTime.UtcNow }", false ),
new Tuple<Object, string, string, bool>( typeof( ICollection<DateTime> ), String.Empty, "new SimpleCollection<DateTime>(){ DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ), DateTime.UtcNow }", false ),
new Tuple<Object, string, string, bool>( typeof( ISet<DateTime> ), String.Empty, "new HashSet<DateTime>(){ DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ), DateTime.UtcNow }", false ),
new Tuple<Object, string, string, bool>( typeof( IList<DateTime> ), String.Empty, "new List<DateTime>(){ DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ), DateTime.UtcNow }", false ),
new Tuple<Object, string, string, bool>( typeof( IDictionary<String, DateTime> ), String.Empty, "new Dictionary<String, DateTime>(){ { \"Yesterday\", DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ) }, { \"Today\", DateTime.UtcNow } }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( "MsgPack.Serialization.AddOnlyCollection`1", new []{ typeof( DateTime ).FullName } ), String.Empty, "new AddOnlyCollection<DateTime>(){ DateTime.UtcNow.Subtract( TimeSpan.FromDays( 1 ) ), DateTime.UtcNow }", false ),
new Tuple<Object, string, string, bool>( typeof( Object ), String.Empty, "new MessagePackObject( 1 )", true ),
new Tuple<Object, string, string, bool>( typeof( Object[] ), String.Empty, "new Object []{ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", true ),
new Tuple<Object, string, string, bool>( typeof( ArrayList ), String.Empty, "new ArrayList(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( typeof( Hashtable ), String.Empty, "new Hashtable(){ { new MessagePackObject( \"1\" ), new MessagePackObject( 1 ) }, { new MessagePackObject( \"2\" ), new MessagePackObject( 2 ) } }", false ),
new Tuple<Object, string, string, bool>( typeof( List<Object> ), String.Empty, "new List<Object>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( typeof( Dictionary<Object, Object> ), String.Empty, "new Dictionary<Object, Object>(){ { new MessagePackObject( \"1\" ), new MessagePackObject( 1 ) }, { new MessagePackObject( \"2\" ), new MessagePackObject( 2 ) } }", false ),
new Tuple<Object, string, string, bool>( typeof( Collection<Object> ), String.Empty, "new Collection<Object>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( "MsgPack.Serialization.StringKeyedCollection`1", new [] { typeof( Object ).FullName } ), String.Empty, "new StringKeyedCollection<Object>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( typeof( ObservableCollection<Object> ), String.Empty, "new ObservableCollection<Object>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( typeof( HashSet<Object> ), String.Empty, "new HashSet<Object>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( typeof( ICollection<Object> ), String.Empty, "new SimpleCollection<Object>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( typeof( ISet<Object> ), String.Empty, "new HashSet<Object>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( typeof( IList<Object> ), String.Empty, "new List<Object>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( typeof( IDictionary<Object, Object> ), String.Empty, "new Dictionary<Object, Object>(){ { new MessagePackObject( \"1\" ), new MessagePackObject( 1 ) }, { new MessagePackObject( \"2\" ), new MessagePackObject( 2 ) } }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( "MsgPack.Serialization.AddOnlyCollection`1", new [] { typeof( Object ).FullName } ), String.Empty, "new AddOnlyCollection<Object>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( "MsgPack.MessagePackObject", new String[ 0 ] ), String.Empty, "new MessagePackObject( 1 )", true ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( "MsgPack.MessagePackObject[]", new String[ 0 ] ), String.Empty, "new MessagePackObject []{ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", true ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( List<> ).FullName, new [] { "MsgPack.MessagePackObject" } ), String.Empty, "new List<MessagePackObject>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( Dictionary<,> ).FullName, new [] { "MsgPack.MessagePackObject", "MsgPack.MessagePackObject" } ), String.Empty, "new Dictionary<MessagePackObject, MessagePackObject>(){ { new MessagePackObject( \"1\" ), new MessagePackObject( 1 ) }, { new MessagePackObject( \"2\" ), new MessagePackObject( 2 ) } }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( Collection<> ).FullName, new [] { "MsgPack.MessagePackObject" } ), String.Empty, "new Collection<MessagePackObject>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( "MsgPack.Serialization.StringKeyedCollection`1", new [] { "MsgPack.MessagePackObject" } ), String.Empty, "new StringKeyedCollection<MessagePackObject>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( ObservableCollection<> ).FullName, new [] { "MsgPack.MessagePackObject" } ), String.Empty, "new ObservableCollection<MessagePackObject>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( HashSet<> ).FullName, new [] { "MsgPack.MessagePackObject" } ), String.Empty, "new HashSet<MessagePackObject>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( ICollection<> ).FullName, new [] { "MsgPack.MessagePackObject" } ), String.Empty, "new SimpleCollection<MessagePackObject>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( ISet<> ).FullName, new [] { "MsgPack.MessagePackObject" } ), String.Empty, "new HashSet<MessagePackObject>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( IList<> ).FullName, new [] { "MsgPack.MessagePackObject" } ), String.Empty, "new List<MessagePackObject>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( typeof( IDictionary<,> ).FullName, new [] { "MsgPack.MessagePackObject", "MsgPack.MessagePackObject" } ), String.Empty, "new Dictionary<MessagePackObject, MessagePackObject>(){ { new MessagePackObject( \"1\" ), new MessagePackObject( 1 ) }, { new MessagePackObject( \"2\" ), new MessagePackObject( 2 ) } }", false ),
new Tuple<Object, string, string, bool>( new Tuple<String, String[]>( "MsgPack.Serialization.AddOnlyCollection`1", new [] { "MsgPack.MessagePackObject" } ), String.Empty, "new AddOnlyCollection<MessagePackObject>(){ new MessagePackObject( 1 ), new MessagePackObject( 2 ) }", false ),
};
var __desktopOnly =
new HashSet<Type>()
{
typeof( ArrayList ),
typeof( Hashtable )
};
var __notInSLWP =
new HashSet<String>()
{
ToTypeName( typeof( KeyValuePair<string, Complex> ) ),
ToTypeName( typeof( BigInteger ) ),
ToTypeName( typeof( Complex ) ),
};
var __notInNet35 =
new HashSet<String>()
{
ToTypeName( new Tuple<String, String[]>( typeof( ObservableCollection<> ).FullName, new [] { "MsgPack.MessagePackObject" } ) ),
ToTypeName( new Tuple<String, String[]>( typeof( ISet<> ).FullName, new [] { "MsgPack.MessagePackObject" } ) ),
ToTypeName( typeof( ISet<Object> ) ),
ToTypeName( typeof( ObservableCollection<object> ) ),
ToTypeName( typeof( ISet<DateTime> ) ),
ToTypeName( typeof( ObservableCollection<DateTime> ) ),
ToTypeName( typeof( KeyValuePair<string, Complex> ) ),
ToTypeName( new Tuple<String, String[]>( typeof( Tuple<,,,> ).FullName, new [] { "System.Int32", "System.String", "MsgPack.MessagePackObject", "System.Object" } ) ),
ToTypeName( typeof( BigInteger ) ),
ToTypeName( typeof( Complex ) ),
};
// Root
foreach( Tuple<Object, string, string, bool> __item in __fields )
{
String __typeName;
if( __item.Item1 is Type )
{
__typeName = ToTypeName( __item.Item1 as Type );
}
else
{
__typeName = ToTypeName( __item.Item1 as Tuple<String, String[]> );
}
var __asType = __item.Item1 as Type;
if( __desktopOnly.Contains( __asType ) && forIos )
{
// skip
continue;
}
if( __typeName.StartsWith( "System.Tuple<" ) && forIos )
{
// skip
continue;
}
if( __asType != null && __desktopOnly.Contains( __asType ) )
{
#>
#if !NETFX_CORE && !SILVERLIGHT
<#+
}
else if( __notInNet35.Contains( __typeName ) )
{
if(__notInSLWP.Contains( __typeName ) )
{
#>
#if !NETFX_35 && !WINDOWS_PHONE
<#+
}
else
{
#>
#if !NETFX_35
<#+
}
}
#>
[Test]
public void Test<#= ToFieldName( __item ) #>()
{
this.TestCoreWithAutoVerify( <#= __item.Item3 == "null" ? "default( object )" : __item.Item3 #>, this.GetSerializationContext() );
}
[Test]
public void Test<#= ToFieldName( __item ) #>Array()
{
this.TestCoreWithAutoVerify( Enumerable.Repeat( <#= __item.Item3 == "null" ? "default( object )" : __item.Item3 #>, 2 ).ToArray(), this.GetSerializationContext() );
}
<#+
if( !( __item.Item1 is Type ) || !( __item.Item1 as Type ).IsValueType )
{
#>
[Test]
public void Test<#= ToFieldName( __item ) #>Null()
{
this.TestCoreWithAutoVerify( default( <#= __item.Item1 is Type ? ToTypeName( __item.Item1 as Type ) : ToTypeName( __item.Item1 as Tuple<string,string[]> ) #> ), this.GetSerializationContext() );
}
[Test]
public void Test<#= ToFieldName( __item ) #>ArrayNull()
{
this.TestCoreWithAutoVerify( default( <#= __item.Item1 is Type ? ToTypeName( __item.Item1 as Type ) : ToTypeName( __item.Item1 as Tuple<string,string[]> ) #>[] ), this.GetSerializationContext() );
}
<#+
}
if( __asType != null && __desktopOnly.Contains( __asType ) )
{
#>
#endif // !NETFX_CORE && !SILVERLIGHT
<#+
}
else if( __notInNet35.Contains( __typeName ) )
{
if(__notInSLWP.Contains( __typeName ) )
{
#>
#endif // !NETFX_35 && !WINDOWS_PHONE
<#+
}
else
{
#>
#endif // !NETFX_35
<#+
}
}
}
// In object
if ( !forIos )
{
// Not needed because generation itself has been done.
#>
[Test]
public void TestComplexTypeGeneratedEnclosure_WithShortcut()
{
SerializerDebugging.AvoidsGenericSerializer = false;
try
{
var target = new ComplexTypeGeneratedEnclosure();
target.Initialize();
this.TestCoreWithVerifiable( target, this.GetSerializationContext() );
}
finally
{
SerializerDebugging.AvoidsGenericSerializer = false;
}
}
[Test]
public void TestComplexTypeGeneratedEnclosure_WithoutShortcut()
{
SerializerDebugging.AvoidsGenericSerializer = true;
try
{
var target = new ComplexTypeGeneratedEnclosure();
target.Initialize();
this.TestCoreWithVerifiable( target, this.GetSerializationContext() );
}
finally
{
SerializerDebugging.AvoidsGenericSerializer = false;
}
}
[Test]
public void TestComplexTypeGeneratedEnclosureArray_WithShortcut()
{
SerializerDebugging.AvoidsGenericSerializer = false;
try
{
this.TestCoreWithVerifiable( Enumerable.Repeat( 0, 2 ).Select( _ => new ComplexTypeGeneratedEnclosure().Initialize() ).ToArray(), this.GetSerializationContext() );
}
finally
{
SerializerDebugging.AvoidsGenericSerializer = false;
}
}
[Test]
public void TestComplexTypeGeneratedEnclosureArray_WithoutShortcut()
{
SerializerDebugging.AvoidsGenericSerializer = true;
try
{
this.TestCoreWithVerifiable( Enumerable.Repeat( 0, 2 ).Select( _ => new ComplexTypeGeneratedEnclosure().Initialize() ).ToArray(), this.GetSerializationContext() );
}
finally
{
SerializerDebugging.AvoidsGenericSerializer = false;
}
}
<#+
// In nested object
#>
[Test]
public void TestComplexTypeGenerated_WithShortcut()
{
SerializerDebugging.AvoidsGenericSerializer = false;
try
{
var target = new ComplexTypeGenerated();
target.Initialize();
this.TestCoreWithVerifiable( target, this.GetSerializationContext() );
}
finally
{
SerializerDebugging.AvoidsGenericSerializer = false;
}
}
[Test]
public void TestComplexTypeGenerated_WithoutShortcut()
{
SerializerDebugging.AvoidsGenericSerializer = true;
try
{
var target = new ComplexTypeGenerated();
target.Initialize();
this.TestCoreWithVerifiable( target, this.GetSerializationContext() );
}
finally
{
SerializerDebugging.AvoidsGenericSerializer = false;
}
}
[Test]
public void TestComplexTypeGeneratedArray_WithShortcut()
{
SerializerDebugging.AvoidsGenericSerializer = false;
try
{
this.TestCoreWithVerifiable( Enumerable.Repeat( 0, 2 ).Select( _ => new ComplexTypeGenerated().Initialize() ).ToArray(), this.GetSerializationContext() );
}
finally
{
SerializerDebugging.AvoidsGenericSerializer = false;
}
}
[Test]
public void TestComplexTypeGeneratedArray_WithoutShortcut()
{
SerializerDebugging.AvoidsGenericSerializer = true;
try
{
this.TestCoreWithVerifiable( Enumerable.Repeat( 0, 2 ).Select( _ => new ComplexTypeGenerated().Initialize() ).ToArray(), this.GetSerializationContext() );
}
finally
{
SerializerDebugging.AvoidsGenericSerializer = false;
}
}
<#+
} // !forIOS
#>
private void TestCoreWithAutoVerify<T>( T value, SerializationContext context )
{
var target = this.CreateTarget<T>( context );
using ( var buffer = new MemoryStream() )
{
target.Pack( buffer, value );
buffer.Position = 0;
T unpacked = target.Unpack( buffer );
buffer.Position = 0;
AutoMessagePackSerializerTest.Verify( value, unpacked );
}
}
private void TestCoreWithVerifiable<T>( T value, SerializationContext context )
where T : IVerifiable<T>
{
var target = this.CreateTarget<T>( context );
using ( var buffer = new MemoryStream() )
{
target.Pack( buffer, value );
buffer.Position = 0;
T unpacked = target.Unpack( buffer );
buffer.Position = 0;
unpacked.Verify( value );
}
}
private void TestCoreWithVerifiable<T>( T[] value, SerializationContext context )
where T : IVerifiable<T>
{
var target = this.CreateTarget<T[]>( context );
using ( var buffer = new MemoryStream() )
{
target.Pack( buffer, value );
buffer.Position = 0;
T[] unpacked = target.Unpack( buffer );
buffer.Position = 0;
Assert.That( unpacked.Length, Is.EqualTo( value.Length ) );
for( int i = 0; i < unpacked.Length; i ++ )
{
try
{
unpacked[ i ].Verify( value[ i ] );
}
#if MSTEST
catch( Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AssertFailedException ae )
{
throw new Microsoft.VisualStudio.TestPlatform.UnitTestFramework.AssertFailedException( i.ToString(), ae );
}
#else
catch( AssertionException ae )
{
throw new AssertionException( i.ToString(), ae );
}
#endif
}
}
}
private static FILETIME ToFileTime( DateTime dateTime )
{
var fileTime = dateTime.ToFileTimeUtc();
return new FILETIME(){ dwHighDateTime = unchecked( ( int )( fileTime >> 32 ) ), dwLowDateTime = unchecked( ( int )( fileTime & 0xffffffff ) ) };
}
}
}
<#+
}
private static string ToTypeName( Type type )
{
if( !type.IsGenericType )
{
return type.Name;
}
return type.Name.Remove( type.Name.IndexOf( '`' ) ) + "<" + String.Join( ", ", type.GetGenericArguments().Select( item => item.Name ) ) + ">";
}
private static string ToTypeName( Tuple<string, string[]> tuple )
{
if( tuple.Item2 == null || tuple.Item2.Length == 0 )
{
return tuple.Item1;
}
return tuple.Item1.Remove( tuple.Item1.IndexOf( '`' ) ) + "<" + String.Join( ", ", tuple.Item2 ) + ">";
}
private static string ToFieldName( Tuple<Object, string, string, bool> tuple )
{
if( !String.IsNullOrWhiteSpace( tuple.Item2 ) )
{
return tuple.Item2;
}
else if( tuple.Item1 is Type )
{
var type = tuple.Item1 as Type;
var typeName = ( type.IsArray ? type.GetElementType() : type ).Name;
var suffix = type.IsArray ? "ArrayField" : "Field";
int index = type.Name.IndexOf( '`' );
if( index < 0 )
{
return typeName + suffix;
}
else
{
return typeName.Remove( index ) + String.Join( String.Empty, type.GetGenericArguments().Select( item => item.Name ) ) + suffix;
}
}
else if( tuple.Item1 is Tuple<string, string[]> )
{
var items = tuple.Item1 as Tuple<string, string[]>;
var first = items.Item1.Substring( items.Item1.LastIndexOf( '.' ) + 1 );
int indexOfBackQuat = first.IndexOf( '`' );
if( 0 <= indexOfBackQuat )
{
first = first.Remove( indexOfBackQuat );
}
int indexOfBracket = first.IndexOf( '[' );
if( 0 <= indexOfBracket )
{
first = first.Remove( indexOfBracket ) + "Array";
}
return first + "_" + String.Join( "_", items.Item2.Select( item => item.Substring( item.LastIndexOf( '.' ) + 1 ) ) ) + "Field";
}
else
{
throw new NotImplementedException( tuple.Item1.GetType().FullName );
}
}
private static string GetSimpleInitializer( Tuple<Object, string, string, bool> tuple )
{
int index = tuple.Item3.IndexOf( '{' );
if( index < 0 )
{
return tuple.Item3;
}
else
{
return tuple.Item3.Remove( index );
}
}
#>