use crate::{
metadata::{
identity::AssemblyIdentity,
method::{Method, MethodRc},
typesystem::{CilFlavor, TypeRegistry},
},
test::MethodBuilder,
};
use std::sync::Arc;
pub fn create_empty_method() -> Arc<Method> {
MethodBuilder::new().with_name("TestConstructor").build()
}
pub fn create_method_with_params(param_types: Vec<CilFlavor>) -> Arc<Method> {
MethodBuilder::with_param_types("TestConstructor", param_types).build()
}
pub fn create_empty_constructor() -> MethodRc {
MethodBuilder::new().with_name("EmptyConstructor").build()
}
pub fn create_constructor_with_params(param_types: Vec<CilFlavor>) -> MethodRc {
MethodBuilder::with_param_types("AttributeConstructor", param_types).build()
}
pub fn get_test_type_registry() -> Arc<TypeRegistry> {
static TEST_REGISTRY: std::sync::OnceLock<Arc<TypeRegistry>> = std::sync::OnceLock::new();
TEST_REGISTRY
.get_or_init(|| {
let identity = AssemblyIdentity::parse("CustomAttributeTestAssembly, Version=1.0.0.0")
.expect("Failed to parse test assembly identity");
Arc::new(TypeRegistry::new(identity).expect("Failed to create TypeRegistry"))
})
.clone()
}
pub fn create_constructor_with_params_and_registry(
param_types: Vec<CilFlavor>,
registry: &Arc<TypeRegistry>,
) -> MethodRc {
MethodBuilder::with_param_types("AttributeConstructor", param_types)
.build_with_registry(Some(registry))
}