use crate::{emulation::engine::context::EmulationContext, metadata::token::Token};
impl EmulationContext {
#[must_use]
pub fn find_method(
&self,
type_namespace: &str,
type_name: &str,
method_name: &str,
) -> Option<Token> {
let cil_type = self.get_type_by_name(type_namespace, type_name)?;
cil_type.find_method(method_name).map(|m| m.token)
}
#[must_use]
pub fn find_methods(
&self,
type_namespace: &str,
type_name: &str,
method_name: &str,
) -> Vec<Token> {
let Some(cil_type) = self.get_type_by_name(type_namespace, type_name) else {
return Vec::new();
};
cil_type
.find_methods(method_name)
.iter()
.map(|m| m.token)
.collect()
}
#[must_use]
pub fn find_static_method(
&self,
type_namespace: &str,
type_name: &str,
method_name: &str,
) -> Option<Token> {
let cil_type = self.get_type_by_name(type_namespace, type_name)?;
cil_type
.find_method(method_name)
.filter(|m| m.is_static())
.map(|m| m.token)
}
#[must_use]
pub fn find_constructor(&self, type_namespace: &str, type_name: &str) -> Option<Token> {
self.find_method(type_namespace, type_name, ".ctor")
}
#[must_use]
pub fn find_constructors(&self, type_namespace: &str, type_name: &str) -> Vec<Token> {
self.find_methods(type_namespace, type_name, ".ctor")
}
}