コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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>());
        }
コード例 #8
0
        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);
        }
コード例 #9
0
        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);
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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);
        }
コード例 #12
0
        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>());
        }