コード例 #1
0
        public void GenericInputTypeIsSolved(ClassType t, string methodName, Type connectedType, int methodParameterIndex,
                                             Type expectedInputType)
        {
            Type methodDeclaringType   = t == ClassType.Plain ? typeof(C) : typeof(D <>);
            FunctionCallNodeModel call = GraphModel.CreateNode <FunctionCallNodeModel>("funcNode", Vector2.zero);

            call.GraphModel = GraphModel;
            call.MethodInfo = methodDeclaringType.GetMethod(methodName);
            Assert.NotNull(call.MethodInfo);
            var param = call.MethodInfo.GetParameters()[methodParameterIndex];

            call.DefineNode();
            var p = new PortModel
            {
                Direction = Direction.Output,
                PortType  = PortType.Data,
                DataType  = connectedType.GenerateTypeHandle(Stencil),
            };
            var parameterPort = call.GetPortForParameter(param.Name);

            call.OnConnection(parameterPort, p);
            Assert.That(parameterPort.DataType, Is.EqualTo(expectedInputType.GenerateTypeHandle(Stencil)));
        }
コード例 #2
0
        public void GenericOutputTypeIsSolved(ClassType t, string methodName, Type connectedType, int methodParameterIndex,
                                              Type expectedOutputType)
        {
            Type methodDeclaringType   = t == ClassType.Plain ? typeof(C) : typeof(D <>);
            FunctionCallNodeModel call = GraphModel.CreateNode <FunctionCallNodeModel>("funcNode", Vector2.zero);

            call.GraphModel = GraphModel;
            call.MethodInfo = methodDeclaringType.GetMethod(methodName);
            Assert.That(call.MethodInfo, Is.Not.Null);
            call.DefineNode();

            IPortModel parameterPort;

            if (methodParameterIndex == k_InstanceIndex)
            {
                Assert.That(call.MethodInfo.IsStatic || call.MethodInfo.IsConstructor, Is.False);
                parameterPort = call.InstancePort;
            }
            else
            {
                var param = call.MethodInfo.GetParameters()[methodParameterIndex];
                parameterPort = call.GetPortForParameter(param.Name);
            }
            var p = new PortModel
            {
                Direction = Direction.Output,
                PortType  = PortType.Data,
                DataType  = connectedType.GenerateTypeHandle(Stencil),
            };

            call.OnConnection(parameterPort, p);
            if (expectedOutputType != typeof(void))
            {
                Assert.That(call.OutputPort.DataType, Is.EqualTo(expectedOutputType.GenerateTypeHandle(Stencil)));
            }
        }