@@ -9,55 +9,55 @@ public void BoxUnbox()
99 var obj = ( BoxedValue < int > ) 42 ;
1010 Assert . AreEqual ( 42 . GetHashCode ( ) , obj . GetHashCode ( ) ) ;
1111 Assert . AreEqual ( 42 , obj . Unbox ( ) ) ;
12- Assert . AreEqual ( 42 , ( int ) obj ) ;
12+ Assert . AreEqual ( 42 , obj ) ;
1313 Assert . AreEqual ( typeof ( int ) , obj . GetType ( ) ) ;
1414 }
1515
16- // [TestMethod]
17- // public void Unwrap()
18- // {
19- // object? obj = null;
20- // Assert.IsNull(BoxedValue<int>.GetTypedReference(obj));
21- //
22- // obj = 42;
23- // Assert.AreEqual(42, BoxedValue<int>.GetTypedReference(obj).Value );
24- //
25- // obj = string.Empty;
26- // Assert.ThrowsException<ArgumentException>(() => BoxedValue<int>.GetTypedReference(obj));
27- // }
28- //
29- // [TestMethod]
30- // public void ToUntypedReference()
31- // {
32- // ValueType obj = BoxedValue<int>.Box(42);
33- // Assert.AreEqual(42, obj);
34- // }
35- //
36- // private struct MutableStruct
37- // {
38- // public int Value;
39- // }
40- //
41- // [TestMethod]
42- // public void BitwiseCopyImmutable()
43- // {
44- // var boxed1 = (BoxedValue<int>)42;
45- // var boxed2 = boxed1.Copy();
46- // Assert.AreNotSame(boxed1, boxed2);
47- // Assert.AreEqual(42, boxed1);
48- // Assert.AreEqual(42, boxed2);
49- // }
50- //
51- // [TestMethod]
52- // public void BitwiseCopyMutable()
53- // {
54- // var boxed1 = (BoxedValue<MutableStruct>)new MutableStruct();
55- // var boxed2 = boxed1.Copy();
56- // Assert.AreNotSame(boxed1, boxed2);
57- //
58- // boxed1.Value .Value = 42;
59- // boxed2.Value .Value = 43;
60- //
61- // Assert.AreNotEqual(boxed1.Value .Value, boxed2.Value .Value);
62- // }
16+ [ TestMethod ]
17+ public void Unwrap ( )
18+ {
19+ object ? obj = null ;
20+ Assert . IsNull ( BoxedValue < int > . GetTypedReference ( obj ) ) ;
21+
22+ obj = 42 ;
23+ Assert . AreEqual ( 42 , BoxedValue < int > . GetTypedReference ( obj ) ) ;
24+
25+ obj = string . Empty ;
26+ Assert . ThrowsException < ArgumentException > ( ( ) => BoxedValue < int > . GetTypedReference ( obj ) ) ;
27+ }
28+
29+ [ TestMethod ]
30+ public void ToUntypedReference ( )
31+ {
32+ ValueType obj = BoxedValue < int > . Box ( 42 ) ;
33+ Assert . AreEqual ( 42 , obj ) ;
34+ }
35+
36+ private struct MutableStruct
37+ {
38+ public int Value ;
39+ }
40+
41+ [ TestMethod ]
42+ public void BitwiseCopyImmutable ( )
43+ {
44+ var boxed1 = ( BoxedValue < int > ) 42 ;
45+ var boxed2 = boxed1 . Copy ( ) ;
46+ Assert . AreNotSame ( boxed1 , boxed2 ) ;
47+ Assert . AreEqual ( 42 , boxed1 ) ;
48+ Assert . AreEqual ( 42 , boxed2 ) ;
49+ }
50+
51+ [ TestMethod ]
52+ public void BitwiseCopyMutable ( )
53+ {
54+ var boxed1 = ( BoxedValue < MutableStruct > ) new MutableStruct ( ) ;
55+ var boxed2 = boxed1 . Copy ( ) ;
56+ Assert . AreNotSame ( boxed1 , boxed2 ) ;
57+
58+ boxed1 . Unbox ( ) . Value = 42 ;
59+ boxed2 . Unbox ( ) . Value = 43 ;
60+
61+ Assert . AreNotEqual ( boxed1 . Unbox ( ) . Value , boxed2 . Unbox ( ) . Value ) ;
62+ }
6363}
0 commit comments