Ejemplo n.º 1
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            List <PropertyDescriptor>    descs = new List <PropertyDescriptor>();
            PropertyDescriptorCollection coll  = TypeDescriptor.GetProperties(_provider, attributes, true);

            foreach (PropertyDescriptor d in coll)
            {
                descs.Add(d);
            }

            ScriptDocument doc = _provider.Script;

            if (doc != null)
            {
                Dictionary <string, dynamic> config = new Dictionary <string, dynamic>(_provider.Config);

                _provider.Config.Clear();

                foreach (DynamicNodeConfigProperty p in doc.Configuration)
                {
                    // Copy across any valid properties
                    if (config.ContainsKey(p.Name) && p.CheckType(config[p.Name]))
                    {
                        _provider.Config[p.Name] = config[p.Name];
                    }
                    else
                    {
                        _provider.Config[p.Name] = p.DefaultValue;
                    }

                    List <Attribute> attrs = new List <Attribute>();
                    attrs.Add(new CategoryAttribute("Node Config"));

                    if (!String.IsNullOrWhiteSpace(p.Description))
                    {
                        attrs.Add(new DescriptionAttribute(p.Description));
                    }

                    if (typeof(IDocumentObject).IsAssignableFrom(p.PropertyType))
                    {
                        attrs.Add(new TypeConverterAttribute(typeof(DocumentChoiceConverter <>).MakeGenericType(p.PropertyType)));
                    }

                    DynamicNodePropertyDescriptor custom = new DynamicNodePropertyDescriptor(p, attrs.ToArray());
                    custom.PropertyChanged += new EventHandler(custom_PropertyChanged);
                    descs.Add(custom);
                }
            }

            return(new PropertyDescriptorCollection(descs.ToArray()));
        }
Ejemplo n.º 2
0
        PropertyDescriptorCollection ICustomTypeDescriptor.GetProperties(Attribute[] attributes)
        {
            List<PropertyDescriptor> descs = new List<PropertyDescriptor>();
            PropertyDescriptorCollection coll = TypeDescriptor.GetProperties(_provider, attributes, true);

            foreach (PropertyDescriptor d in coll)
            {
                descs.Add(d);
            }

            ScriptDocument doc = _provider.Script;

            if (doc != null)
            {
                Dictionary<string, dynamic> config = new Dictionary<string, dynamic>(_provider.Config);

                _provider.Config.Clear();

                foreach (DynamicNodeConfigProperty p in doc.Configuration)
                {
                    // Copy across any valid properties
                    if (config.ContainsKey(p.Name) && p.CheckType(config[p.Name]))
                    {
                        _provider.Config[p.Name] = config[p.Name];
                    }
                    else
                    {
                        _provider.Config[p.Name] = p.DefaultValue;
                    }

                    List<Attribute> attrs = new List<Attribute>();
                    attrs.Add(new CategoryAttribute("Node Config"));

                    if (!String.IsNullOrWhiteSpace(p.Description))
                    {
                        attrs.Add(new DescriptionAttribute(p.Description));
                    }

                    if (typeof(IDocumentObject).IsAssignableFrom(p.PropertyType))
                    {
                        attrs.Add(new TypeConverterAttribute(typeof(DocumentChoiceConverter<>).MakeGenericType(p.PropertyType)));
                    }

                    DynamicNodePropertyDescriptor custom = new DynamicNodePropertyDescriptor(p, attrs.ToArray());
                    custom.PropertyChanged += new EventHandler(custom_PropertyChanged);
                    descs.Add(custom);
                }
            }

            return new PropertyDescriptorCollection(descs.ToArray());
        }