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