Exemplo n.º 1
0
        /// <summary>
        /// Returns the property this one is linked to.
        /// </summary>
        /// <param name="linkBroken">Is true if a link was found but it does not work.</param>
        /// <returns>The info of the property this is linked to.</returns>
        public DesignerPropertyInfo GetLinkedProperty(object obj, out bool linkBroken)
        {
            linkBroken = false;

            if (string.IsNullOrEmpty(_linkedToProperty))
            {
                return(new DesignerPropertyInfo());
            }

            DesignerPropertyInfo dpi = DesignerProperty.GetDesignerProperty(obj.GetType(), _linkedToProperty);

            // if we are linked to a DesignerNodeProperty we get the information of its assigned property
            DesignerNodeProperty dnp = dpi.Attribute as DesignerNodeProperty;

            if (dnp == null)
            {
                return(dpi);
            }

            Attachments.Attachment attach = (Attachments.Attachment)obj;

            // check if a valid property is associated
            object objvalue = dpi.Property.GetValue(obj, null);

            string value = dnp.GetDisplayValue(objvalue);

            if (string.IsNullOrEmpty(value) || value == Resources.DesignerNodePropertyNone)
            {
                linkBroken = true;

                return(new DesignerPropertyInfo());
            }

            // return the property we are pointing at
            return(DesignerProperty.GetDesignerProperty(attach.Node.GetType(), value));
        }
        public override void SetProperty(DesignerPropertyInfo property, object obj)
        {
            base.SetProperty(property, obj);

            Nodes.Node node = null;

            if (obj is Nodes.Node)
            {
                node = (Nodes.Node)obj;
            }
            else if (obj is Attachments.Attachment)
            {
                node = ((Attachments.Attachment)obj).Node;
            }
            else
            {
                throw new Exception(string.Format(Resources.ExceptionDesignerAttributeCouldNotRetrieveNode, obj));
            }

            string[] excludedProperties = node.GetNodePropertyExcludedProperties();

            DesignerNodeProperty attribute = (DesignerNodeProperty)property.Attribute;

            comboBox.Items.Add(Resources.DesignerNodePropertyNone);

            IList <DesignerPropertyInfo> properties = node.GetDesignerProperties();

            foreach (DesignerPropertyInfo dpi in properties)
            {
                bool supported = false;

                // check if the property is allowed
                foreach (Type supportedType in attribute.SupportedTypes)
                {
                    if (dpi.Property.PropertyType == supportedType)
                    {
                        supported = true;

                        break;
                    }
                }

                // skip this property if it is not supported
                if (!supported)
                {
                    continue;
                }

                // check if the node denies using this property
                foreach (string excludedProperty in excludedProperties)
                {
                    if (dpi.Property.Name == excludedProperty)
                    {
                        supported = false;

                        break;
                    }
                }

                // skip this property if it is not supported
                if (!supported)
                {
                    continue;
                }

                // add the property to the list
                comboBox.Items.Add(dpi.Property.Name);
            }

            comboBox.Text = (string)property.Property.GetValue(obj, null);

            if (comboBox.Text.Length < 1)
            {
                comboBox.SelectedIndex = 0;
            }
        }