コード例 #1
0
ファイル: DragEventTests.cs プロジェクト: veboys/UIForia
        public void CreateAnnotationInvalidParameterCount()
        {
            CompileException exception = Assert.Throws <CompileException>(() => { MockApplication.Setup <DragTestThing_CreateAnnotationInvalidParameterCount>(); });

            Assert.IsTrue(exception.Message.Contains(
                              CompileException.TooManyInputAnnotationArguments("CreateDrag", typeof(DragTestThing_CreateAnnotationInvalidParameterCount), typeof(OnDragCreateAttribute), typeof(MouseInputEvent), 2)
                              .Message));
        }
コード例 #2
0
ファイル: InputCompiler.cs プロジェクト: klanggames/UIForia
        private static void GetDragCreators(MethodInfo methodInfo, ParameterInfo[] parameters, object[] customAttributes, StructList <InputHandler> handlers)
        {
            for (int i = 0; i < customAttributes.Length; i++)
            {
                OnDragCreateAttribute attr = customAttributes[i] as OnDragCreateAttribute;

                if (attr == null)
                {
                    continue;
                }

                if (parameters.Length > 1)
                {
                    throw CompileException.TooManyInputAnnotationArguments(methodInfo.Name, methodInfo.DeclaringType, typeof(OnDragCreateAttribute), typeof(MouseInputEvent), parameters.Length);
                }

                if (parameters.Length == 1)
                {
                    if (!typeof(MouseInputEvent).IsAssignableFrom(parameters[0].ParameterType))
                    {
                        throw CompileException.InvalidInputAnnotation(methodInfo.Name, methodInfo.DeclaringType, typeof(OnDragCreateAttribute), typeof(MouseInputEvent), parameters[0].ParameterType);
                    }
                }

                if (!typeof(DragEvent).IsAssignableFrom(methodInfo.ReturnType))
                {
                    throw CompileException.InvalidDragCreatorAnnotationReturnType(methodInfo.Name, methodInfo.DeclaringType, methodInfo.ReturnType);
                }


                if (!methodInfo.IsPublic || methodInfo.IsStatic)
                {
                    throw new CompileException($"{methodInfo.DeclaringType}.{methodInfo} must be an instance method and marked as public in order to be used as a drag creator");
                }

                handlers.Add(new InputHandler()
                {
                    descriptor = new InputHandlerDescriptor()
                    {
                        eventPhase    = attr.phase,
                        modifiers     = attr.modifiers,
                        requiresFocus = false,
                        handlerType   = InputEventType.DragCreate
                    },
                    methodInfo        = methodInfo,
                    parameterType     = parameters.Length >= 1 ? parameters[0].ParameterType : null,
                    useEventParameter = parameters.Length == 1
                });
            }
        }