Skip to content

Commit 71031a8

Browse files
authored
Added List::Insert and Dictionary::Remove (#2)
1 parent 3720ae9 commit 71031a8

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

src/system.rs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,21 @@ impl<T> List<T> {
6969
add(self, element, method);
7070
}
7171

72+
pub fn insert(&mut self, index: i32, element: &'static mut T) {
73+
let method = self.get_class()
74+
.get_methods()
75+
.iter()
76+
.find(|method| method.get_name() == Some(String::from("Insert")))
77+
.unwrap();
78+
79+
let insert = unsafe {
80+
std::mem::transmute::<_, extern "C" fn(&mut Self, i32, &'static mut T, &MethodInfo)>(
81+
method.method_ptr,
82+
)
83+
};
84+
85+
insert(self, index, element, method);
86+
}
7287
pub fn len(&self) -> usize {
7388
self.size as _
7489
}
@@ -168,7 +183,30 @@ impl<TKey, TValue> Dictionary<TKey, TValue> {
168183

169184
add(self, key, value, method.method_info);
170185
}
171-
186+
pub fn remove(&self, key: TKey) {
187+
let method = self.get_class()
188+
.get_virtual_method("Remove")
189+
.unwrap();
190+
191+
let remove = unsafe {
192+
std::mem::transmute::<_, extern "C" fn(&Self, TKey, &MethodInfo)>(
193+
method.method_info.method_ptr,
194+
)
195+
};
196+
remove(self, key, method.method_info);
197+
}
198+
pub fn get_count(&self) -> i32 {
199+
let method = self.get_class()
200+
.get_virtual_method("get_Count")
201+
.unwrap();
202+
203+
let count = unsafe {
204+
std::mem::transmute::<_, extern "C" fn(&Self) -> i32 >(
205+
method.method_info.method_ptr,
206+
)
207+
};
208+
count(self)
209+
}
172210
pub fn try_get_value<'a>(&self, key: TKey, value: &'a mut TValue) -> bool {
173211
let method = self.get_class()
174212
.get_virtual_method("TryGetValue")

0 commit comments

Comments
 (0)