File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -89,6 +89,20 @@ public StackItem this[PrimitiveType key]
89
89
/// <param name="referenceCounter">The reference counter to be used.</param>
90
90
public Map ( IReferenceCounter ? referenceCounter = null ) : base ( referenceCounter ) { }
91
91
92
+ /// <summary>
93
+ /// Create a new map with the specified dictionary and reference counter.
94
+ /// </summary>
95
+ /// <param name="dictionary">Dictionary</param>
96
+ /// <param name="referenceCounter">Reference Counter</param>
97
+ public Map ( IDictionary < PrimitiveType , StackItem > dictionary , IReferenceCounter ? referenceCounter = null )
98
+ : this ( referenceCounter )
99
+ {
100
+ foreach ( var ( k , v ) in dictionary )
101
+ {
102
+ this [ k ] = v ;
103
+ }
104
+ }
105
+
92
106
public override void Clear ( )
93
107
{
94
108
if ( IsReadOnly ) throw new InvalidOperationException ( "The map is readonly, can not clear." ) ;
Original file line number Diff line number Diff line change 12
12
using Microsoft . VisualStudio . TestTools . UnitTesting ;
13
13
using Neo . VM ;
14
14
using Neo . VM . Types ;
15
+ using System . Collections . Generic ;
15
16
using System . Numerics ;
16
17
17
18
namespace Neo . Test
@@ -93,10 +94,11 @@ public void TestHashCode()
93
94
94
95
itemA = new Map { [ true ] = false , [ 0 ] = 1 } ;
95
96
itemB = new Map { [ true ] = false , [ 0 ] = 1 } ;
96
- itemC = new Map { [ true ] = false , [ 0 ] = 2 } ;
97
+ itemC = new Map ( new Dictionary < PrimitiveType , StackItem > ( ) { [ true ] = false , [ 0 ] = 2 } ) ;
97
98
98
99
Assert . AreEqual ( itemB . GetHashCode ( ) , itemA . GetHashCode ( ) ) ;
99
100
Assert . AreNotEqual ( itemC . GetHashCode ( ) , itemA . GetHashCode ( ) ) ;
101
+ Assert . HasCount ( 2 , itemC as Map ) ;
100
102
101
103
// Test CompoundType GetHashCode for subitems
102
104
var junk = new Array { true , false , 0 } ;
You can’t perform that action at this time.
0 commit comments