-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code missing from repo but present on NuGet
These changes were decompiled using dotpeek. Chances are these changes were made on Jake's machine directly, then published direct to NuGet, but the code was never pushed to GitHub. If ever SqlObjectHydrator needs to change again, the changes should be based on this branch
- Loading branch information
Showing
30 changed files
with
660 additions
and
639 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
using SqlObjectHydrator.ILEmitting; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using SqlObjectHydrator.ILEmitting; | ||
|
||
namespace SqlObjectHydrator.Caching | ||
{ | ||
internal class MappingCache<T> | ||
{ | ||
public MappingCache( Func<IDataReader, Dictionary<MappingEnum, object>, Dictionary<Tuple<int,Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>, T> func, Dictionary<MappingEnum, object> mappings ) | ||
public MappingCache( | ||
System.Func<IDataReader, Dictionary<MappingEnum, object>, Dictionary<Tuple<int, Type>, System.Func<IDataRecord, Dictionary<MappingEnum, object>, object>>, T> func, | ||
Dictionary<MappingEnum, object> mappings ) | ||
{ | ||
Func = func; | ||
Mappings = mappings; | ||
TypeMaps = new Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>(); | ||
this.Func = func; | ||
this.Mappings = mappings; | ||
this.TypeMaps = new Dictionary<Tuple<int, Type>, System.Func<IDataRecord, Dictionary<MappingEnum, object>, object>>(); | ||
} | ||
|
||
private Func<IDataReader, Dictionary<MappingEnum, object>, Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>>, T> Func { get; set; } | ||
private System.Func<IDataReader, Dictionary<MappingEnum, object>, Dictionary<Tuple<int, Type>, System.Func<IDataRecord, Dictionary<MappingEnum, object>, object>>, T> Func { get; set; } | ||
|
||
private Dictionary<MappingEnum, object> Mappings { get; set; } | ||
private Dictionary<Tuple<int, Type>, Func<IDataRecord, Dictionary<MappingEnum, object>, object>> TypeMaps { get; set; } | ||
|
||
public T Run( IDataReader dataReader ) | ||
private Dictionary<Tuple<int, Type>, System.Func<IDataRecord, Dictionary<MappingEnum, object>, object>> TypeMaps { get; set; } | ||
|
||
public T Run( IDataReader dataReader ) | ||
{ | ||
return Func( dataReader, Mappings, TypeMaps ); | ||
return this.Func( dataReader, this.Mappings, this.TypeMaps ); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,30 @@ | ||
using System; | ||
using SqlObjectHydrator.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Dynamic; | ||
using System.Linq; | ||
using SqlObjectHydrator.Configuration; | ||
|
||
namespace SqlObjectHydrator.ClassMapping | ||
{ | ||
internal static class ClassMapGenerator | ||
{ | ||
public static ClassMapResult Generate<T>( IDataReader dataReader, Type configurationType = null ) where T : new() | ||
public static ClassMapResult Generate<T>( | ||
IDataReader dataReader, | ||
Type configurationType = null ) | ||
where T : new() | ||
{ | ||
var mappings = new Mapping(); | ||
if ( configurationType != null ) | ||
Mapping mapping = new Mapping(); | ||
if ( configurationType != (Type)null ) | ||
( (IObjectHydratorConfiguration)Activator.CreateInstance( configurationType ) ).Mapping( (IMapping)mapping ); | ||
ClassMapResult classMapResult = new ClassMapResult() | ||
{ | ||
var configuration = (IObjectHydratorConfiguration)Activator.CreateInstance( configurationType ); | ||
configuration.Mapping( mappings ); | ||
} | ||
|
||
var classMapResult = new ClassMapResult | ||
{ | ||
Mappings = mappings | ||
Mappings = mapping | ||
}; | ||
|
||
var baseType = ( typeof( T ).IsGenericType && typeof( T ).GetGenericTypeDefinition() == typeof( List<> ) ) ? typeof( T ).GetGenericArguments()[ 0 ] : typeof( T ); | ||
if ( !mappings.TableMaps.ContainsValue( baseType ) ) | ||
mappings.TableMaps.Add( 0, baseType ); | ||
|
||
mappings.TableMaps = mappings.TableMaps.OrderBy( x => x.Key ).ToDictionary( x => x.Key, x => x.Value ); | ||
|
||
Type type = !typeof( T ).IsGenericType || !( typeof( T ).GetGenericTypeDefinition() == typeof( List<> ) ) ? typeof( T ) : typeof( T ).GetGenericArguments()[ 0 ]; | ||
if ( !mapping.TableMaps.ContainsValue( type ) ) | ||
mapping.TableMaps.Add( 0, type ); | ||
mapping.TableMaps = mapping.TableMaps.OrderBy<KeyValuePair<int, Type>, int>( (Func<KeyValuePair<int, Type>, int>)( x => x.Key ) ).ToDictionary<KeyValuePair<int, Type>, int, Type>( (Func<KeyValuePair<int, Type>, int>)( x => x.Key ), (Func<KeyValuePair<int, Type>, Type>)( x => x.Value ) ); | ||
return classMapResult; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
using System.Collections.Generic; | ||
using System.Collections.Generic; | ||
|
||
namespace SqlObjectHydrator.ClassMapping | ||
{ | ||
internal class ClassMapResult | ||
{ | ||
public ClassMapResult() | ||
{ | ||
TempDataStorage = new List<List<Dictionary<int, object>>>(); | ||
this.TempDataStorage = new List<List<Dictionary<int, object>>>(); | ||
} | ||
|
||
public List<List<Dictionary<int, object>>> TempDataStorage { get; private set; } | ||
|
||
public Mapping Mappings { get; set; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,105 +1,99 @@ | ||
using SqlObjectHydrator.Configuration; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Data; | ||
using System.Dynamic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
using SqlObjectHydrator.Configuration; | ||
|
||
namespace SqlObjectHydrator.ClassMapping | ||
{ | ||
internal class Mapping : IMapping | ||
{ | ||
public Dictionary<PropertyInfo, PropertyMap> PropertyMaps { get; set; } | ||
|
||
public Dictionary<int, Type> TableMaps { get; set; } | ||
|
||
public List<DictionaryTableJoin> DictionaryTableJoins { get; set; } | ||
|
||
public List<TableJoinMap> TableJoins { get; set; } | ||
|
||
public Dictionary<KeyValuePair<Type, Type>, object> Joins { get; set; } | ||
|
||
public Dictionary<Type, object> VariableTableTypes { get; set; } | ||
|
||
public Mapping() | ||
{ | ||
PropertyMaps = new Dictionary<PropertyInfo, PropertyMap>(); | ||
TableMaps = new Dictionary<int, Type>(); | ||
DictionaryTableJoins = new List<DictionaryTableJoin>(); | ||
TableJoins = new List<TableJoinMap>(); | ||
Joins = new Dictionary<KeyValuePair<Type, Type>, object>(); | ||
VariableTableTypes = new Dictionary<Type, object>(); | ||
this.PropertyMaps = new Dictionary<PropertyInfo, PropertyMap>(); | ||
this.TableMaps = new Dictionary<int, Type>(); | ||
this.DictionaryTableJoins = new List<DictionaryTableJoin>(); | ||
this.TableJoins = new List<TableJoinMap>(); | ||
this.Joins = new Dictionary<KeyValuePair<Type, Type>, object>(); | ||
this.VariableTableTypes = new Dictionary<Type, object>(); | ||
} | ||
|
||
void IMapping.Table<T>( int id ) | ||
{ | ||
TableMaps.Add( id, typeof( T ) ); | ||
this.TableMaps.Add( id, typeof( T ) ); | ||
} | ||
|
||
void IMapping.PropertyMap<T, TResult>( Expression<Func<T, TResult>> property, Func<IDataRecord, TResult> setAction ) | ||
void IMapping.PropertyMap<T, TResult>( | ||
Expression<Func<T, TResult>> property, | ||
Func<IDataRecord, TResult> setAction ) | ||
{ | ||
PropertyMaps.Add( GetPropertyInfo<T>( property.ToString().Split( '.' ).Last() ), new PropertyMap( setAction ) ); | ||
this.PropertyMaps.Add( Mapping.GetPropertyInfo<T>( ( (IEnumerable<string>)property.ToString().Split( '.' ) ).Last<string>() ), new PropertyMap( (Delegate)setAction ) ); | ||
} | ||
|
||
public void PropertyMap<T, TResult>( Expression<Func<T, TResult>> property, string columnName ) | ||
{ | ||
PropertyMaps.Add( GetPropertyInfo<T>( property.ToString().Split( '.' ).Last() ), new PropertyMap( columnName ) ); | ||
this.PropertyMaps.Add( Mapping.GetPropertyInfo<T>( ( (IEnumerable<string>)property.ToString().Split( '.' ) ).Last<string>() ), new PropertyMap( columnName ) ); | ||
} | ||
|
||
public void PropertyMap<T, TResult>( Expression<Func<T, TResult>> property, int columnId ) | ||
{ | ||
PropertyMaps.Add( GetPropertyInfo<T>( property.ToString().Split( '.' ).Last() ), new PropertyMap( columnId ) ); | ||
this.PropertyMaps.Add( Mapping.GetPropertyInfo<T>( ( (IEnumerable<string>)property.ToString().Split( '.' ) ).Last<string>() ), new PropertyMap( columnId ) ); | ||
} | ||
|
||
private static PropertyInfo GetPropertyInfo<T>( string name ) | ||
{ | ||
var propertyInfo = typeof( T ).GetProperty( name ) ?? typeof( T ).GetProperty( name, BindingFlags.Instance | BindingFlags.NonPublic ); | ||
return propertyInfo; | ||
PropertyInfo property = typeof( T ).GetProperty( name ); | ||
if ( (object)property == null ) | ||
property = typeof( T ).GetProperty( name, BindingFlags.Instance | BindingFlags.NonPublic ); | ||
return property; | ||
} | ||
|
||
void IMapping.TableJoin<TParent, TChild>( Func<TParent, TChild, bool> canJoin, Action<TParent, List<TChild>> listSet ) | ||
void IMapping.TableJoin<TParent, TChild>( | ||
Func<TParent, TChild, bool> canJoin, | ||
Action<TParent, List<TChild>> listSet ) | ||
{ | ||
TableJoins.Add( new TableJoinMap | ||
this.TableJoins.Add( new TableJoinMap() | ||
{ | ||
ChildType = typeof( TChild ), | ||
ParentType = typeof( TParent ), | ||
CanJoin = canJoin, | ||
ListSet = listSet | ||
CanJoin = (object)canJoin, | ||
ListSet = (object)listSet | ||
} ); | ||
} | ||
|
||
void IMapping.Join<TParent, TChild>( Action<TParent, List<TChild>> listSet ) | ||
{ | ||
Joins.Add( new KeyValuePair<Type, Type>( typeof( TParent ), typeof( TChild ) ), listSet ); | ||
this.Joins.Add( new KeyValuePair<Type, Type>( typeof( TParent ), typeof( TChild ) ), (object)listSet ); | ||
} | ||
|
||
void IMapping.AddJoin( Func<ITableJoin, ITableJoinMap> func ) | ||
{ | ||
var tableJoinMap = func( new TableJoin() ); | ||
if ( tableJoinMap is DictionaryTableJoin ) | ||
{ | ||
var dictionaryTableJoin = tableJoinMap as DictionaryTableJoin; | ||
DictionaryTableJoins.Add( dictionaryTableJoin ); | ||
TableMaps.Add( dictionaryTableJoin.ChildTable, typeof( ExpandoObject ) ); | ||
} | ||
ITableJoinMap tableJoinMap = func( (ITableJoin)new TableJoin() ); | ||
if ( !( tableJoinMap is DictionaryTableJoin ) ) | ||
return; | ||
DictionaryTableJoin dictionaryTableJoin = tableJoinMap as DictionaryTableJoin; | ||
this.DictionaryTableJoins.Add( dictionaryTableJoin ); | ||
this.TableMaps.Add( dictionaryTableJoin.ChildTable, typeof( ExpandoObject ) ); | ||
} | ||
|
||
void IMapping.VariableTableType<T>( Func<IDataRecord, Type> action ) | ||
{ | ||
VariableTableTypes.Add( typeof( T ), action ); | ||
} | ||
} | ||
|
||
internal class TableJoinMap | ||
{ | ||
public Type ParentType { get; set; } | ||
public Type ChildType { get; set; } | ||
public object CanJoin { get; set; } | ||
public object ListSet { get; set; } | ||
} | ||
|
||
internal class TableJoin : ITableJoin | ||
{ | ||
public IDictionaryJoinCondition<T> DictionaryTableJoin<T>() where T : new() | ||
{ | ||
return new DictionaryTableJoin<T>(); | ||
this.VariableTableTypes.Add( typeof( T ), (object)action ); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
namespace SqlObjectHydrator.ClassMapping | ||
namespace SqlObjectHydrator.ClassMapping | ||
{ | ||
internal enum PropertyMapType | ||
{ | ||
Func, | ||
ColumnId, | ||
ColumnName | ||
ColumnName, | ||
} | ||
} | ||
} |
Oops, something went wrong.