Ejemplo n.º 1
0
        public void CreateAnnotationInvalidParameter()
        {
            CompileException exception = Assert.Throws <CompileException>(() => { MockApplication.Setup <DragTestThing_CreateAnnotationInvalidParameter>(); });

            Assert.IsTrue(
                exception.Message.Contains(CompileException.InvalidInputAnnotation("CreateDrag", typeof(DragTestThing_CreateAnnotationInvalidParameter), typeof(OnDragCreateAttribute), typeof(MouseInputEvent), typeof(int)).Message));
        }
Ejemplo n.º 2
0
        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
                });
            }
        }