22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System ;
5+ using System . Collections . Generic ;
56using System . Linq ;
67using System . Linq . Expressions ;
78using FileContextCore . Utilities ;
@@ -60,8 +61,37 @@ System.Collections.Generic.List<IEntityType> concreteEntityTypes
6061
6162 LabelTarget returnLabelTarget = Expression . Label ( typeof ( object ) ) ;
6263
63- Expression [ ] blockExpressions
64- = new Expression [ ]
64+ Expression [ ] blockExpressions = CreateExpressions ( entityTypeParameter , concreteEntityTypes , returnLabelTarget , valueBufferParameter ) ;
65+
66+ foreach ( IEntityType concreteEntityType in concreteEntityTypes . Skip ( 1 ) )
67+ {
68+ blockExpressions [ 0 ] = ProcessExpression ( entityTypeParameter , concreteEntityType , returnLabelTarget , valueBufferParameter , blockExpressions ) ;
69+ }
70+
71+ return Expression . Lambda < Func < IEntityType , ValueBuffer , object > > (
72+ Expression . Block ( blockExpressions ) ,
73+ entityTypeParameter ,
74+ valueBufferParameter ) ;
75+ }
76+
77+ private Expression ProcessExpression ( ParameterExpression entityTypeParameter , IEntityType concreteEntityType ,
78+ LabelTarget returnLabelTarget , ParameterExpression valueBufferParameter , Expression [ ] blockExpressions )
79+ {
80+ return Expression . IfThenElse (
81+ Expression . Equal (
82+ entityTypeParameter ,
83+ Expression . Constant ( concreteEntityType ) ) ,
84+ Expression . Return (
85+ returnLabelTarget ,
86+ _entityMaterializerSource
87+ . CreateMaterializeExpression ( concreteEntityType , valueBufferParameter ) ) ,
88+ blockExpressions [ 0 ] ) ;
89+ }
90+
91+ private Expression [ ] CreateExpressions ( ParameterExpression entityTypeParameter , List < IEntityType > concreteEntityTypes ,
92+ LabelTarget returnLabelTarget , ParameterExpression valueBufferParameter )
93+ {
94+ return new Expression [ ]
6595 {
6696 Expression . IfThen (
6797 Expression . Equal (
@@ -76,25 +106,6 @@ Expression[] blockExpressions
76106 returnLabelTarget ,
77107 Expression . Default ( returnLabelTarget . Type ) )
78108 } ;
79-
80- foreach ( IEntityType concreteEntityType in concreteEntityTypes . Skip ( 1 ) )
81- {
82- blockExpressions [ 0 ]
83- = Expression . IfThenElse (
84- Expression . Equal (
85- entityTypeParameter ,
86- Expression . Constant ( concreteEntityType ) ) ,
87- Expression . Return (
88- returnLabelTarget ,
89- _entityMaterializerSource
90- . CreateMaterializeExpression ( concreteEntityType , valueBufferParameter ) ) ,
91- blockExpressions [ 0 ] ) ;
92- }
93-
94- return Expression . Lambda < Func < IEntityType , ValueBuffer , object > > (
95- Expression . Block ( blockExpressions ) ,
96- entityTypeParameter ,
97- valueBufferParameter ) ;
98109 }
99110 }
100111}
0 commit comments