Example #1
0
        /// <summary>
        /// Reads a field value from a DataRow returned by a CAML query
        /// </summary>
        /// <typeparam name="T">The field's associated value type</typeparam>
        /// <param name="dataRowFromCamlResult">The CAML-query-result data row we want to extract a field value from</param>
        /// <param name="fieldInternalName">The key to find the field among the data row cells</param>
        /// <returns>The value extracted from the data row's corresponding cell</returns>
        public T ReadValueFromCamlResultDataRow <T>(DataRow dataRowFromCamlResult, string fieldInternalName)
        {
            IBaseValueReader selectedReader   = this.GetReader(typeof(T));
            object           valueThatWasRead = selectedReader.GetType().GetMethod("ReadValueFromCamlResultDataRow").Invoke(selectedReader, new object[] { dataRowFromCamlResult, fieldInternalName });

            return((T)valueThatWasRead);
        }
Example #2
0
        /// <summary>
        /// Reads a field value from a list item version
        /// </summary>
        /// <typeparam name="T">The field's associated value type</typeparam>
        /// <param name="itemVersion">The list item version we want to extract a field value from</param>
        /// <param name="fieldInternalName">The key to find the field in the item's columns</param>
        /// <returns>The value extracted from the list item's field</returns>
        public T ReadValueFromListItemVersion <T>(SPListItemVersion itemVersion, string fieldInternalName)
        {
            IBaseValueReader selectedReader   = this.GetReader(typeof(T));
            object           valueThatWasRead = selectedReader.GetType().GetMethod("ReadValueFromListItemVersion").Invoke(selectedReader, new object[] { itemVersion, fieldInternalName });

            return((T)valueThatWasRead);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityBindingDetail"/> class.
        /// </summary>
        /// <param name="entityProperty">The entity property.</param>
        /// <param name="valueKey">The value key.</param>
        /// <param name="bindingType">Type of the binding.</param>
        /// <param name="valueWriter">Value writer for the associated value type</param>
        /// <param name="valueReader">Value reader for the associated value type</param>
        public EntityPropertyConversionDetail(PropertyInfo entityProperty, string valueKey, BindingType bindingType, IBaseValueWriter valueWriter, IBaseValueReader valueReader)
        {
            this.EntityProperty = entityProperty;
            this.ValueKey = valueKey;
            this.BindingType = bindingType;

            this.ValueWriter = valueWriter;
            this.ValueReader = valueReader;
        }
        /// <summary>
        /// Fills the entity with values taken from the values collection.
        /// </summary>
        /// <typeparam name="T">The type of the entity.</typeparam>
        /// <param name="entity">The entity.</param>
        /// <param name="listItemVersion">The list item version.</param>
        public void ToEntity <T>(T entity, SPListItemVersion listItemVersion)
        {
            var schema = this.entitySchemaFactory.GetSchema(typeof(T));

            foreach (var binding in schema.PropertyConversionDetails.Where(x => x.BindingType == BindingType.Bidirectional || x.BindingType == BindingType.ReadOnly))
            {
                IBaseValueReader reader = binding.ValueReader;
                var value = reader.GetType()
                            .GetMethod("ReadValueFromListItemVersion")
                            .Invoke(reader, new object[] { listItemVersion, binding.ValueKey });

                binding.EntityProperty.SetValue(entity, value, null);
            }
        }
        /// <summary>
        /// Fills the entity with values taken from the values collection.
        /// </summary>
        /// <typeparam name="T">
        /// The type of the entity.
        /// </typeparam>
        /// <param name="entity">
        /// The entity.
        /// </param>
        /// <param name="dataRow">
        /// The data Row.
        /// </param>
        /// <param name="fieldCollection">
        /// The field Collection.
        /// </param>
        public void ToEntity <T>(T entity, DataRow dataRow, SPFieldCollection fieldCollection)   // TODO: get rid of field collection here... only useful for Write purposes..
        {
            var schema = this.entitySchemaFactory.GetSchema(typeof(T));

            foreach (var binding in schema.PropertyConversionDetails.Where(x => x.BindingType == BindingType.Bidirectional || x.BindingType == BindingType.ReadOnly))
            {
                IBaseValueReader reader = binding.ValueReader;
                var value = reader.GetType()
                            .GetMethod("ReadValueFromCamlResultDataRow")
                            .Invoke(reader, new object[] { fieldCollection.Web, dataRow, binding.ValueKey });

                binding.EntityProperty.SetValue(entity, value, null);
            }
        }
Example #6
0
 private void AddToReadersDictionary(IBaseValueReader reader)
 {
     this.readers.Add(reader.AssociatedValueType, reader);
 }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityBindingDetail"/> class.
        /// </summary>
        /// <param name="entityProperty">The entity property.</param>
        /// <param name="valueKey">The value key.</param>
        /// <param name="bindingType">Type of the binding.</param>
        /// <param name="valueWriter">Value writer for the associated value type</param>
        /// <param name="valueReader">Value reader for the associated value type</param>
        public EntityPropertyConversionDetail(PropertyInfo entityProperty, string valueKey, BindingType bindingType, IBaseValueWriter valueWriter, IBaseValueReader valueReader)
        {
            this.EntityProperty = entityProperty;
            this.ValueKey       = valueKey;
            this.BindingType    = bindingType;

            this.ValueWriter = valueWriter;
            this.ValueReader = valueReader;
        }