Ejemplo n.º 1
0
        public override PropertyDescriptorCollection GetProperties(Attribute[] attributes)
        {
            var properties = base.GetProperties(attributes).Cast <PropertyDescriptor>();

            var bettered = properties.Select(pd =>
            {
                // 找元素名
                if (Element.TryGetOidByName(pd.Name, out ElementOID oid) == false)
                {
                    return(pd);
                }

                bool is_readonly = false;
                Element element  = _instance.FindElement(oid);
                if (element != null && element.Locked)
                {
                    is_readonly = true;
                }

                // 从 .Name 找到 readonly 的应有值
                {
                    List <Attribute> attribs = new List <Attribute>();
                    foreach (Attribute attr in pd.Attributes)
                    {
                        if (attr is ReadOnlyAttribute)
                        {
                            attribs.Add(new ReadOnlyAttribute(is_readonly));
                        }
                        else
                        {
                            attribs.Add(attr);
                        }
                    }
                    return(TypeDescriptor.CreateProperty(typeof(LogicChipItem), pd, attribs.ToArray()));
                }
#if NO
                if (PropertyAttributeReplacements.ContainsKey(pd.PropertyType))
                {
                    return(TypeDescriptor.CreateProperty(typeof(T), pd, PropertyAttributeReplacements[pd.PropertyType].ToArray()));
                }
                else
                {
                    return(pd);
                }
#endif
            });

            return(new PropertyDescriptorCollection(bettered.ToArray()));
        }
Ejemplo n.º 2
0
        void GetField(ChipItem item,
                      string fieldName)
        {
            ElementOID oid     = Element.GetOidByName(fieldName);
            Element    element = _chip.FindElement(oid);

            if (element != null && element.Locked)
            {
                return;
            }

            var info = item.GetType().GetProperty(fieldName);

            _chip.SetElement(oid, (string)info.GetValue(item));
        }