示例#1
0
        /// <summary>
        /// Crée la collection des descripteurs de propriétés.
        /// </summary>
        /// <param name="beanType">Type du bean.</param>
        /// <returns>Collection.</returns>
        private static DocumentFieldDescriptorCollection CreateCollection(Type beanType)
        {
            DocumentFieldDescriptorCollection coll       = new DocumentFieldDescriptorCollection(beanType);
            PropertyDescriptorCollection      properties = TypeDescriptor.GetProperties(beanType);

            foreach (PropertyDescriptor property in properties)
            {
                SearchFieldAttribute fieldAttr = (SearchFieldAttribute)property.Attributes[typeof(SearchFieldAttribute)];
                if (fieldAttr == null)
                {
                    throw new NotSupportedException("Missing SearchFieldAttribute on property " + beanType + "." + property.Name);
                }

                var category = fieldAttr.Category;

                string fieldName = ToCamelCase(property.Name);
                DocumentFieldDescriptor description = new DocumentFieldDescriptor(
                    property.Name,
                    fieldName,
                    property.PropertyType,
                    category);

                coll[description.PropertyName] = description;
            }

            return(coll);
        }
示例#2
0
        /// <summary>
        /// Constructeur.
        /// </summary>
        /// <param name="beanType">Type du bean.</param>
        /// <param name="properties">Collection de propriétés.</param>
        /// <param name="documentTypeName">Nom du contrat (table).</param>
        internal DocumentDefinition(Type beanType, DocumentFieldDescriptorCollection properties, string documentTypeName)
        {
            this.BeanType         = beanType;
            this.Fields           = properties;
            this.DocumentTypeName = documentTypeName;
            foreach (DocumentFieldDescriptor property in properties)
            {
                switch (property.Category)
                {
                case SearchFieldCategory.Id:
                    this.PrimaryKey = property;
                    break;

                case SearchFieldCategory.Search:
                    this.TextField = property;
                    break;

                case SearchFieldCategory.Security:
                    this.SecurityField = property;
                    break;

                default:
                    break;
                }
            }

            if (this.PrimaryKey == null)
            {
                throw new NotSupportedException(beanType + " has no primary key defined.");
            }
        }
示例#3
0
        /// <summary>
        /// Retourne la definition d'un bean.
        /// </summary>
        /// <param name="beanType">Type du bean.</param>
        /// <returns>Description des propriétés.</returns>
        private DocumentDefinition GetDefinitionInternal(Type beanType)
        {
            DocumentDefinition definition;

            if (!_beanDefinitionDictionnary.TryGetValue(beanType, out definition))
            {
                SearchDocumentTypeAttribute documentType = (SearchDocumentTypeAttribute)TypeDescriptor.GetAttributes(beanType)[typeof(SearchDocumentTypeAttribute)];
                if (documentType == null)
                {
                    throw new NotSupportedException("Missing SearchDocumentTypeAttribute on type " + beanType);
                }

                string documentTypeName = documentType.DocumentTypeName;

                DocumentFieldDescriptorCollection properties = CreateCollection(beanType);
                definition = new DocumentDefinition(beanType, properties, documentTypeName);
                _beanDefinitionDictionnary[beanType] = definition;
            }

            return(definition);
        }