Ejemplo n.º 1
0
        public static DynamicTypeDescriptor GetTypeDescriptor(ISysObjectManager mgr, Type type,
                                                              IEnumerable <SysObject> items)
        {
            var res = new DynamicTypeDescriptor(type);

            foreach (var o in items)
            {
                // разбор
                var attributes = GetAttributes(o, type);

                // описание типа
                var sysObjNameAttr =
                    Attribute.GetCustomAttribute(type, typeof(SysObjectNameAttribute)) as SysObjectNameAttribute;
                var typename = sysObjNameAttr != null
                    ? sysObjNameAttr.SysObjectName
                    : type.Name;

                if (typename.EqIgnoreCase(o.ObjectName))
                {
                    //TODO: правильнее было бы передавать все аттрибуты
                    res.AddAttributes(
                        attributes.Where(p => p is DisplayNameAttribute || p is ListViewCaptionAttribute).ToArray());
                    continue;
                }

                var propertyType = GetObjectTrueType(mgr, o);

                //HACK: Добавляем атрибут CustomXmlIgnoreAttribute к свойству
                if (typeof(IList).IsAssignableFrom(propertyType) && propertyType.IsGenericType)
                {
                    var itemType = propertyType.GetGenericArguments().FirstOrDefault();
                    if (
                        itemType != null && (
                            typeof(AddressBook) == itemType ||
                            typeof(IWBPosQLFDetailDesc) == itemType ||
                            typeof(GlobalParamValue).IsAssignableFrom(itemType) ||
                            typeof(EpsConfig).IsAssignableFrom(itemType)) ||
                        typeof(MotionAreaGroupTr).IsAssignableFrom(itemType)
                        )
                    {
                        var attrs = new List <Attribute>(attributes)
                        {
                            new XmlNotIgnoreAttribute()
                        };
                        attributes = attrs.ToArray();
                    }
                }

                var propertyDesc = new DynamicPropertyDescriptor(o.ObjectName, attributes, type, propertyType,
                                                                 o.ObjectDefaultValue);
                res.AddProperty(propertyDesc);
            }
            return(res);
        }
Ejemplo n.º 2
0
        protected void AddPropertyAt(uint i, string[] flagNames)
        {
            string flagName;

            if (i < flagNames.Length && flagNames[i] != null)
            {
                flagName = flagNames[i];
            }
            else
            {
                flagName = $"UnknownFlag_{i}";
            }

            dt.AddProperty(typeof(bool), $"Flag_{i}", GetFlag(i), flagName, "", "", false, false, false);
        }
Ejemplo n.º 3
0
 protected void AddProperty(DynamicTypeDescriptor dt, string name)
 {
     dt.AddProperty(Properties.Find(name, false));
 }