public void CreateDelegateType_StringReturnType_OneStringParameters_Ok() { // Arrange var builder = new DelegateTypeBuilder(); // Act var type = builder.CreateDelegateType(typeof(IDelegateFoo).GetMethod("FooMethod_String_StringIsIn"), ModuleBuilder); var method = type.GetMethod("Invoke"); // Assert Assert.AreEqual(1, method.GetParameters().Length); }
public void CreateDelegateType_AddsArgumentTypeNamesInDelegateName_Ok() { // Arrange var builder = new DelegateTypeBuilder(); // Act var type = builder.CreateDelegateType(typeof(IDelegateFoo).GetMethod("FooMethod_String_StringIsIn"), ModuleBuilder); var method = type.GetMethod("Invoke"); // Assert Assert.AreEqual("FooMethod_String_StringIsIn_String_Proc", type.Name); }
public void CreateDelegateType_StringReturnType_NoParameters_Ok() { // Arrange var builder = new DelegateTypeBuilder(); // Act var type = builder.CreateDelegateType(typeof(IDelegateFoo).GetMethod("FooMethod_String"), ModuleBuilder); var method = type.GetMethod("Invoke"); // Assert Assert.IsNotNull(method); Assert.AreEqual(typeof(string), method.ReturnType); }
public void CreateDelegateType_VoidReturnType_NoParameters_Ok() { // Arrange var builder = new DelegateTypeBuilder(); // Act var type = builder.CreateDelegateType(typeof(IDelegateFoo).GetMethod("FooMethod"), ModuleBuilder); var method = type.GetMethod("Invoke"); // Assert Assert.That(typeof(Delegate).IsAssignableFrom(type)); Assert.AreEqual(typeof(void), method.ReturnType); }
public void CreateDelegateType_StringReturnType_OneStringParametersWithIn_CopiesAttributes() { // Arrange var builder = new DelegateTypeBuilder(); // Act var type = builder.CreateDelegateType(typeof(IDelegateFoo).GetMethod("FooMethod_String_StringIsIn"), ModuleBuilder); var method = type.GetMethod("Invoke"); var parameters = method.GetParameters(); var param = parameters.First(); // Assert Assert.IsNotNull(param.GetCustomAttribute <InAttribute>()); }
public void CreateDelegateType_StringReturnType_OneStringParametersCustomMarshaller_PreservesRefType() { // Arrange var builder = new DelegateTypeBuilder(); // Act var type = builder.CreateDelegateType(typeof(IDelegateFoo).GetMethod("FooMethod_String_StringWithCustomMarshal"), ModuleBuilder); var method = type.GetMethod("Invoke"); var parameters = method.GetParameters(); var param = parameters.First(); var marshal = param.GetCustomAttribute <MarshalAsAttribute>(); // Assert Assert.IsNotNull(marshal); Assert.IsNotNull(marshal.MarshalTypeRef); }
public void CreateDelegateType_StringReturnType_OneStringParametersCustomMarshaller_PreservesRefType() { // Arrange var builder = new DelegateTypeBuilder(); // Act var type = builder.CreateDelegateType(typeof(IDelegateFoo).GetMethod("FooMethod_String_StringWithCustomMarshal"), ModuleBuilder); var method = type.GetMethod("Invoke"); var parameters = method.GetParameters(); var param = parameters.First(); var marshal = param.GetCustomAttribute<MarshalAsAttribute>(); // Assert Assert.IsNotNull(marshal); Assert.IsNotNull(marshal.MarshalTypeRef); }
public void CreateDelegateType_VoidReturnType_NoParameters_Ok() { // Arrange var builder = new DelegateTypeBuilder(); // Act var type = builder.CreateDelegateType(typeof (IDelegateFoo).GetMethod("FooMethod"), ModuleBuilder); var method = type.GetMethod("Invoke"); // Assert Assert.That(typeof(Delegate).IsAssignableFrom(type)); Assert.AreEqual(typeof(void), method.ReturnType); }
public void CreateDelegateType_StringReturnType_OneStringParametersWithIn_CopiesAttributes() { // Arrange var builder = new DelegateTypeBuilder(); // Act var type = builder.CreateDelegateType(typeof(IDelegateFoo).GetMethod("FooMethod_String_StringIsIn"), ModuleBuilder); var method = type.GetMethod("Invoke"); var parameters = method.GetParameters(); var param = parameters.First(); // Assert Assert.IsNotNull(param.GetCustomAttribute<InAttribute>()); }