/// <summary> /// Returns an object reader for the given type that matches the given schema. /// </summary> /// <param name="command">The command associated with the reader.</param> /// <param name="reader">The reader containing the schema to analyze.</param> /// <param name="type">The type to analyze.</param> /// <returns>An ObjectReader for the schema and type.</returns> public static ObjectReader GetObjectReader(IDbCommand command, IDataReader reader, Type type) { SchemaIdentity schemaIdentity = new SchemaIdentity(reader); var key = Tuple.Create(schemaIdentity, type); return(_readerDataCache.GetOrAdd(key, k => new ObjectReader(command, k.Item2, reader))); }
/// <summary> /// Initializes a new instance of the SchemaMappingIdentity class. /// </summary> /// <param name="schemaIdentity">The identity of the schema to map to.</param> /// <param name="recordReader">The reader to use to read the objects from the stream.</param> /// <param name="mappingType">The type of mapping operation.</param> public SchemaMappingIdentity(SchemaIdentity schemaIdentity, IRecordReader recordReader, SchemaMappingType mappingType) { if (recordReader == null) { throw new ArgumentNullException("recordReader"); } // save the values away for later RecordReader = recordReader; _mappingType = mappingType; _schemaIdentity = schemaIdentity; // we know that we are going to store this in a hashtable, so pre-calculate the hashcode unchecked { // base the hashcode on the mapping type, target graph, and schema contents _hashCode = (int)_mappingType; _hashCode *= 13; _hashCode += RecordReader.GetHashCode(); _hashCode *= 13; _hashCode += schemaIdentity.GetHashCode(); } }