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);
        }