@@ -40,7 +40,7 @@ public Type GenericTypeDef
40
40
private Type m_genericTypeDef ;
41
41
42
42
// Cached ToArray method for Lists
43
- public MethodInfo GenericToArrayMethod
43
+ public MethodInfo CppListToArrayMethod
44
44
{
45
45
get => GetGenericToArrayMethod ( ) ;
46
46
}
@@ -60,7 +60,7 @@ private IEnumerable GetEnumerable()
60
60
{
61
61
if ( m_enumerable == null && Value != null )
62
62
{
63
- m_enumerable = Value as IEnumerable ?? GetEnumerableFromIl2CppList ( ) ;
63
+ m_enumerable = Value as IEnumerable ?? EnumerateWithReflection ( ) ;
64
64
}
65
65
return m_enumerable ;
66
66
}
@@ -100,21 +100,45 @@ private PropertyInfo GetItemProperty()
100
100
return m_itemProperty ;
101
101
}
102
102
103
- private IEnumerable GetEnumerableFromIl2CppList ( )
103
+ private IEnumerable EnumerateWithReflection ( )
104
104
{
105
105
if ( Value == null ) return null ;
106
106
107
107
if ( GenericTypeDef == typeof ( Il2CppSystem . Collections . Generic . List < > ) )
108
108
{
109
- return ( IEnumerable ) GenericToArrayMethod ? . Invoke ( Value , new object [ 0 ] ) ;
109
+ return ( IEnumerable ) CppListToArrayMethod ? . Invoke ( Value , new object [ 0 ] ) ;
110
+ }
111
+ else if ( GenericTypeDef == typeof ( Il2CppSystem . Collections . Generic . HashSet < > ) )
112
+ {
113
+ return CppHashSetToMono ( ) ;
110
114
}
111
115
else
112
116
{
113
- return ConvertIListToMono ( ) ;
117
+ return CppIListToMono ( ) ;
118
+ }
119
+ }
120
+
121
+ private IEnumerable CppHashSetToMono ( )
122
+ {
123
+ var set = new HashSet < object > ( ) ;
124
+
125
+ // invoke GetEnumerator
126
+ var enumerator = Value . GetType ( ) . GetMethod ( "GetEnumerator" ) . Invoke ( Value , null ) ;
127
+ // get the type of it
128
+ var enumeratorType = enumerator . GetType ( ) ;
129
+ // reflect MoveNext and Current
130
+ var moveNext = enumeratorType . GetMethod ( "MoveNext" ) ;
131
+ var current = enumeratorType . GetProperty ( "Current" ) ;
132
+ // iterate
133
+ while ( ( bool ) moveNext . Invoke ( enumerator , null ) )
134
+ {
135
+ set . Add ( current . GetValue ( enumerator ) ) ;
114
136
}
137
+
138
+ return set ;
115
139
}
116
140
117
- private IList ConvertIListToMono ( )
141
+ private IList CppIListToMono ( )
118
142
{
119
143
try
120
144
{
0 commit comments