Esempio n. 1
0
        public override bool CompileTimeValidate(MethodBase method)
        {
            if (typeof(Form).IsAssignableFrom(method.DeclaringType))
            {
                return(true);
            }

            if (method.DeclaringType == null)
            {
                return(false);
            }

            var errorMessage =
                $"UIThread aspect must be used in a Form. [Assembly: {method.DeclaringType.Assembly.FullName}, Class: {method.DeclaringType.FullName}, Method: {method.Name}]";

            Message.Write(method, SeverityType.Error, "UIThreadFormError01", errorMessage);

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// The method needs to be applied control side (target site).
        /// </summary>
        /// <param name="method"></param>
        /// <returns></returns>
        public override bool CompileTimeValidate(MethodBase method)
        {
            if (method.IsStatic)
            {
                Message.Write(new Message(SeverityType.Error,
                                          "AG0001",
                                          String.Format("Error in the custom attribute UIThreadAttribute on type '{0}', method '{1}': the method cannot be static", method.DeclaringType, method.Name),
                                          "UIThreadAttribute"));
            }

            // Ensure method is declared within a Control-derived class
            if (!typeof(Control).IsAssignableFrom(method.DeclaringType) &&
                !typeof(ListViewItem).IsAssignableFrom(method.DeclaringType) &&
                !typeof(DataGridViewRow).IsAssignableFrom(method.DeclaringType))
            {
                Message.Write(new Message(SeverityType.Error,
                                          "AG0002",
                                          String.Format("Error in the custom attribute UIThreadAttribute on type '{0}', method '{1}': the argument '{0}' must derive from System.Windows.Forms.Control.", method.DeclaringType, method.Name),
                                          "UIThreadAttribute"));
            }

            return(base.CompileTimeValidate(method));
        }