Пример #1
0
        private static Type GetObjectTrueType(ISysObjectManager mgr, SysObject obj)
        {
            var type = CustomProperty.DefaultType;

            if (obj.ObjectDataType.HasValue)
            {
                type = mgr.GetTypeBySysObjectId(obj.ObjectDataType.Value);
            }

            if (type == null)
            {
                throw new DeveloperException(
                          string.Format(
                              "Для свойства '{0}' объекта '{1}' не удалось определить тип данных '{2}'. Проверьте создан ли объект с данным типом.",
                              obj.ObjectName, obj.ObjectEntityCode, obj.ObjectDataType));
            }

            // если перед нами коллекция - "ну что ж, приступим ..."
            if (obj.ObjectRelationship == Relationship.Many)
            {
                type = typeof(WMSBusinessCollection <>).MakeGenericType(type);
            }
            else
            {
                // Если не указано значение по умолчанию - значит может быть и null
                if (obj.ObjectDefaultValue == null)
                {
                    type = type.GetNullAssignableType();
                }
            }

            return(type);
        }
Пример #2
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);
        }