1010
1111namespace System . Runtime . Serialization . Formatters . Tests
1212{
13- public static class BinaryFormatterHelpers
14- {
15- internal static T Clone < T > ( T obj )
16- {
13+ public static class BinaryFormatterHelpers
14+ {
15+ internal static T Clone < T > ( T obj )
16+ {
1717 // https://github.com/dotnet/corefx/issues/18942 - Binary serialization still WIP on AOT platforms.
1818 if ( RuntimeInformation . FrameworkDescription . StartsWith ( ".NET Native" ) )
1919 return obj ;
2020
21- var f = new BinaryFormatter ( ) ;
22- using ( var s = new MemoryStream ( ) )
23- {
24- f . Serialize ( s , obj ) ;
25- s . Position = 0 ;
26- return ( T ) f . Deserialize ( s ) ;
27- }
28- }
21+ var f = new BinaryFormatter ( ) ;
22+ using ( var s = new MemoryStream ( ) )
23+ {
24+ f . Serialize ( s , obj ) ;
25+ s . Position = 0 ;
26+ return ( T ) f . Deserialize ( s ) ;
27+ }
28+ }
2929
3030 internal static Lazy < T > Clone < T > ( Lazy < T > lazy )
3131 {
@@ -40,36 +40,36 @@ internal static Lazy<T> Clone<T>(Lazy<T> lazy)
4040 }
4141
4242 public static void AssertRoundtrips < T > ( T expected , params Func < T , object > [ ] additionalGetters )
43- where T : Exception
44- {
45- for ( int i = 0 ; i < 2 ; i ++ )
46- {
47- if ( i > 0 ) // first time without stack trace, second time with
48- {
49- try { throw expected ; }
50- catch { }
51- }
43+ where T : Exception
44+ {
45+ for ( int i = 0 ; i < 2 ; i ++ )
46+ {
47+ if ( i > 0 ) // first time without stack trace, second time with
48+ {
49+ try { throw expected ; }
50+ catch { }
51+ }
5252
53- // Serialize/deserialize the exception
54- T actual = Clone ( expected ) ;
53+ // Serialize/deserialize the exception
54+ T actual = Clone ( expected ) ;
5555
56- // Verify core state
57- if ( ! PlatformDetection . IsFullFramework ) // On full framework, line number is method body start
58- {
59- Assert . Equal ( expected . StackTrace , actual . StackTrace ) ;
60- }
61- Assert . Equal ( expected . Data , actual . Data ) ;
62- Assert . Equal ( expected . Message , actual . Message ) ;
63- Assert . Equal ( expected . Source , actual . Source ) ;
64- Assert . Equal ( expected . ToString ( ) , actual . ToString ( ) ) ;
65- Assert . Equal ( expected . HResult , actual . HResult ) ;
56+ // Verify core state
57+ if ( ! PlatformDetection . IsFullFramework ) // On full framework, line number may be method body start
58+ {
59+ Assert . Equal ( expected . StackTrace , actual . StackTrace ) ;
60+ Assert . Equal ( expected . ToString ( ) , actual . ToString ( ) ) ; // includes stack trace
61+ }
62+ Assert . Equal ( expected . Data , actual . Data ) ;
63+ Assert . Equal ( expected . Message , actual . Message ) ;
64+ Assert . Equal ( expected . Source , actual . Source ) ;
65+ Assert . Equal ( expected . HResult , actual . HResult ) ;
6666
67- // Verify optional additional state
68- foreach ( Func < T , object > getter in additionalGetters )
69- {
70- Assert . Equal ( getter ( expected ) , getter ( actual ) ) ;
71- }
72- }
73- }
74- }
67+ // Verify optional additional state
68+ foreach ( Func < T , object > getter in additionalGetters )
69+ {
70+ Assert . Equal ( getter ( expected ) , getter ( actual ) ) ;
71+ }
72+ }
73+ }
74+ }
7575}
0 commit comments