@@ -25,9 +25,10 @@ public class ExpressionParser
25
25
26
26
private readonly ParsingConfig _parsingConfig ;
27
27
private readonly MethodFinder _methodFinder ;
28
- private readonly KeywordsHelper _keywordsHelper ;
28
+ private readonly IKeywordsHelper _keywordsHelper ;
29
29
private readonly TextParser _textParser ;
30
30
private readonly IExpressionHelper _expressionHelper ;
31
+ private readonly ITypeFinder _typeFinder ;
31
32
private readonly Dictionary < string , object > _internals ;
32
33
private readonly Dictionary < string , object > _symbols ;
33
34
@@ -73,6 +74,7 @@ public ExpressionParser([CanBeNull] ParameterExpression[] parameters, [NotNull]
73
74
_textParser = new TextParser ( expression ) ;
74
75
_methodFinder = new MethodFinder ( _parsingConfig ) ;
75
76
_expressionHelper = new ExpressionHelper ( _parsingConfig ) ;
77
+ _typeFinder = new TypeFinder ( _parsingConfig , _keywordsHelper ) ;
76
78
}
77
79
78
80
void ProcessParameters ( ParameterExpression [ ] parameters )
@@ -1242,7 +1244,7 @@ Expression ParseNew()
1242
1244
_textParser . NextToken ( ) ;
1243
1245
}
1244
1246
1245
- newType = FindType ( newTypeName ) ;
1247
+ newType = _typeFinder . FindTypeByName ( newTypeName , new [ ] { _it , _parent , _root } , false ) ;
1246
1248
if ( newType == null )
1247
1249
{
1248
1250
throw ParseError ( _textParser . CurrentToken . Pos , Res . TypeNotFound , newTypeName ) ;
@@ -1654,54 +1656,6 @@ Expression ParseMemberAccess(Type type, Expression instance)
1654
1656
throw ParseError ( errorPos , Res . UnknownPropertyOrField , id , TypeHelper . GetTypeName ( type ) ) ;
1655
1657
}
1656
1658
1657
- Type FindType ( string name )
1658
- {
1659
- _keywordsHelper . TryGetValue ( name , out object type ) ;
1660
-
1661
- Type result = type as Type ;
1662
- if ( result != null )
1663
- {
1664
- return result ;
1665
- }
1666
-
1667
- if ( _it != null && _it . Type . Name == name )
1668
- {
1669
- return _it . Type ;
1670
- }
1671
-
1672
- if ( _parent != null && _parent . Type . Name == name )
1673
- {
1674
- return _parent . Type ;
1675
- }
1676
-
1677
- if ( _root != null && _root . Type . Name == name )
1678
- {
1679
- return _root . Type ;
1680
- }
1681
-
1682
- if ( _it != null && _it . Type . Namespace + "." + _it . Type . Name == name )
1683
- {
1684
- return _it . Type ;
1685
- }
1686
-
1687
- if ( _parent != null && _parent . Type . Namespace + "." + _parent . Type . Name == name )
1688
- {
1689
- return _parent . Type ;
1690
- }
1691
-
1692
- if ( _root != null && _root . Type . Namespace + "." + _root . Type . Name == name )
1693
- {
1694
- return _root . Type ;
1695
- }
1696
-
1697
- if ( _parsingConfig . AllowNewToEvaluateAnyType && _parsingConfig . CustomTypeProvider != null )
1698
- {
1699
- return _parsingConfig . CustomTypeProvider . ResolveType ( name ) ;
1700
- }
1701
-
1702
- return null ;
1703
- }
1704
-
1705
1659
Expression ParseAggregate ( Expression instance , Type elementType , string methodName , int errorPos , bool isQueryable )
1706
1660
{
1707
1661
var oldParent = _parent ;
@@ -1806,7 +1760,7 @@ private Type ResolveTypeFromArgumentExpression(string functionName, Expression a
1806
1760
throw ParseError ( _textParser . CurrentToken . Pos , Res . FunctionRequiresOneNotNullArg , functionName , typeName ) ;
1807
1761
}
1808
1762
1809
- Type resultType = FindType ( typeName ) ;
1763
+ Type resultType = _typeFinder . FindTypeByName ( typeName , new [ ] { _it , _parent , _root } , true ) ;
1810
1764
if ( resultType == null )
1811
1765
{
1812
1766
throw ParseError ( _textParser . CurrentToken . Pos , Res . TypeNotFound , typeName ) ;
0 commit comments