Esempio n. 1
0
        /// <summary>
        /// Gets the schema.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The schema for the type.</returns>
        public IEntityBindingSchema GetSchema(Type type)
        {
            var schema = new EntityBindingSchema(type);

            foreach (var entityProperty in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var customAttributes = entityProperty.GetCustomAttributes(typeof(PropertyAttribute), false);
                var propertyDetails = customAttributes.OfType<PropertyAttribute>().FirstOrDefault();
                if (propertyDetails != null)
                {
                    var valueKey = !string.IsNullOrEmpty(propertyDetails.PropertyName) ? propertyDetails.PropertyName : entityProperty.Name;
                    var valueWriter = this.fieldValueWriter.GetValueWriterForType(entityProperty.PropertyType);
                    var valueReader = this.fieldValueReader.GetValueReaderForType(entityProperty.PropertyType);

                    schema.PropertyConversionDetails.Add(
                        new EntityPropertyConversionDetail(
                            entityProperty, 
                            valueKey, 
                            propertyDetails.BindingType,
                            valueWriter,
                            valueReader));
                }
            }

            return schema;
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the schema.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <returns>The schema for the type.</returns>
        public IEntityBindingSchema GetSchema(Type type)
        {
            var schema = new EntityBindingSchema(type);

            foreach (var entityProperty in type.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                var customAttributes = entityProperty.GetCustomAttributes(typeof(PropertyAttribute), false);
                var propertyDetails  = customAttributes.OfType <PropertyAttribute>().FirstOrDefault();
                if (propertyDetails != null)
                {
                    var valueKey    = !string.IsNullOrEmpty(propertyDetails.PropertyName) ? propertyDetails.PropertyName : entityProperty.Name;
                    var valueWriter = this.fieldValueWriter.GetValueWriterForType(entityProperty.PropertyType);
                    var valueReader = this.fieldValueReader.GetValueReaderForType(entityProperty.PropertyType);

                    schema.PropertyConversionDetails.Add(
                        new EntityPropertyConversionDetail(
                            entityProperty,
                            valueKey,
                            propertyDetails.BindingType,
                            valueWriter,
                            valueReader));
                }
            }

            return(schema);
        }