Exemplo n.º 1
0
            /**
             * Using reflection, calls a method on a widget that checks if the name for the property
             * that needs to be set is correct.
             * @param widgetType The widget type on which we need to do the property validity checking.
             * @param propertyName The name of the property that needs to be checked.
             * @throws InvalidPropertyNameException This exception is thrown if the set property name is incorrect.
             */
            private void CheckPropertyName(Type widgetType, String propertyName)
            {
                bool propertyExists = false;

                // we first check to see if the widgetType has that property implemented
                foreach (PropertyInfo pinfo in widgetType.GetProperties())
                {
                    foreach (Attribute attr in pinfo.GetCustomAttributes(false))
                    {
                        if (attr.GetType() == typeof(MoSyncWidgetPropertyAttribute))
                        {
                            MoSyncWidgetPropertyAttribute e = (MoSyncWidgetPropertyAttribute)attr;
                            if (e.Name.ToLower().Equals(propertyName.ToLower()))
                            {
                                propertyExists = true;
                            }
                        }
                    }
                }

                // if the property doesn't exist, we throw a InvalidPropertyNameException
                if (!propertyExists)
                {
                    throw new InvalidPropertyNameException();
                }
            }
            /**
             * Runs a set property operation on the current widget.
             * @param operation The widget operation that needs to be applied on the current widget.
             */
            protected void SetProperty(WidgetOperation operation)
            {
                PropertyInfo pinfo;
                MoSyncWidgetPropertyAttribute pattr = GetPropertyAttribute(operation.Property, out pinfo);
                Exception exception = null;

                try
                {
                    SetProperty(pinfo, operation.Value);
                }
                catch (Exception e)
                {
                    exception = e;
                }
                if (null != exception)
                {
                    if (exception.InnerException is InvalidPropertyValueException)
                    {
                        throw new InvalidPropertyValueException();
                    }
                }
            }