@@ -1045,6 +1045,42 @@ Expression ParseIdentifier()
1045
1045
return expr ;
1046
1046
}
1047
1047
1048
+ //// This could be enum like "MyEnum.Value1"
1049
+ //if (_textParser.CurrentToken.Id == TokenId.Identifier)
1050
+ //{
1051
+ // var parts = new List<string> { _textParser.CurrentToken.Text };
1052
+
1053
+ // _textParser.NextToken();
1054
+ // _textParser.ValidateToken(TokenId.Dot, Res.DotExpected);
1055
+ // while (_textParser.CurrentToken.Id == TokenId.Dot || _textParser.CurrentToken.Id == TokenId.Plus)
1056
+ // {
1057
+ // parts.Add(_textParser.CurrentToken.Text);
1058
+
1059
+ // _textParser.NextToken();
1060
+ // _textParser.ValidateToken(TokenId.Identifier, Res.IdentifierExpected);
1061
+
1062
+ // parts.Add(_textParser.CurrentToken.Text);
1063
+
1064
+ // _textParser.NextToken();
1065
+ // }
1066
+
1067
+ // var enumTypeAsString = string.Join("", parts.Take(parts.Count - 2).ToArray());
1068
+ // var enumType = _typeFinder.FindTypeByName(enumTypeAsString, null, true);
1069
+ // if (enumType == null)
1070
+ // {
1071
+ // throw ParseError(_textParser.CurrentToken.Pos, Res.EnumTypeNotFound, enumTypeAsString);
1072
+ // }
1073
+
1074
+ // string enumValue = parts.Last();
1075
+ // var @enum = TypeHelper.ParseEnum(enumValue, enumType);
1076
+ // if (@enum == null)
1077
+ // {
1078
+ // throw ParseError(_textParser.CurrentToken.Pos, Res.EnumValueNotDefined, enumValue, enumTypeAsString);
1079
+ // }
1080
+
1081
+ // return Expression.Constant(@enum);
1082
+ //}
1083
+
1048
1084
if ( _it != null )
1049
1085
{
1050
1086
return ParseMemberAccess ( null , _it ) ;
@@ -1682,10 +1718,9 @@ Expression ParseMemberAccess(Type type, Expression expression)
1682
1718
}
1683
1719
}
1684
1720
1685
- if ( type . GetTypeInfo ( ) . IsEnum )
1721
+ var @enum = TypeHelper . ParseEnum ( id , type ) ;
1722
+ if ( @enum != null )
1686
1723
{
1687
- var @enum = Enum . Parse ( type , id , true ) ;
1688
-
1689
1724
return Expression . Constant ( @enum ) ;
1690
1725
}
1691
1726
@@ -1722,33 +1757,85 @@ Expression ParseMemberAccess(Type type, Expression expression)
1722
1757
return _expressionHelper . ConvertToExpandoObjectAndCreateDynamicExpression ( expression , type , id ) ;
1723
1758
}
1724
1759
#endif
1725
-
1760
+ // Parse as Lambda
1726
1761
if ( _textParser . CurrentToken . Id == TokenId . Lambda && _it . Type == type )
1727
1762
{
1728
- // This might be an internal variable for use within a lambda expression, so store it as such
1729
- _internals . Add ( id , _it ) ;
1730
- string _previousItName = ItName ;
1763
+ return ParseAsLambda ( id ) ;
1764
+ }
1765
+
1766
+ // This could be enum like "A.B.C.MyEnum.Value1" or "A.B.C+MyEnum.Value1"
1767
+ if ( _textParser . CurrentToken . Id == TokenId . Dot || _textParser . CurrentToken . Id == TokenId . Plus )
1768
+ {
1769
+ return ParseAsEnum ( id ) ;
1770
+ }
1771
+
1772
+ throw ParseError ( errorPos , Res . UnknownPropertyOrField , id , TypeHelper . GetTypeName ( type ) ) ;
1773
+ }
1774
+
1775
+ private Expression ParseAsLambda ( string id )
1776
+ {
1777
+ // This might be an internal variable for use within a lambda expression, so store it as such
1778
+ _internals . Add ( id , _it ) ;
1779
+ string _previousItName = ItName ;
1780
+
1781
+ // Also store ItName (only once)
1782
+ if ( string . Equals ( ItName , KeywordsHelper . KEYWORD_IT ) )
1783
+ {
1784
+ ItName = id ;
1785
+ }
1786
+
1787
+ // next
1788
+ _textParser . NextToken ( ) ;
1789
+
1790
+ LastLambdaItName = ItName ;
1791
+ var exp = ParseConditionalOperator ( ) ;
1731
1792
1732
- // Also store ItName (only once)
1733
- if ( string . Equals ( ItName , KeywordsHelper . KEYWORD_IT ) )
1793
+ // Restore previous context and clear internals
1794
+ _internals . Remove ( id ) ;
1795
+ ItName = _previousItName ;
1796
+
1797
+ return exp ;
1798
+ }
1799
+
1800
+ private Expression ParseAsEnum ( string id )
1801
+ {
1802
+ var parts = new List < string > { id } ;
1803
+
1804
+ while ( _textParser . CurrentToken . Id == TokenId . Dot || _textParser . CurrentToken . Id == TokenId . Plus )
1805
+ {
1806
+ if ( _textParser . CurrentToken . Id == TokenId . Dot || _textParser . CurrentToken . Id == TokenId . Plus )
1734
1807
{
1735
- ItName = id ;
1808
+ parts . Add ( _textParser . CurrentToken . Text ) ;
1809
+ _textParser . NextToken ( ) ;
1736
1810
}
1737
1811
1738
- // next
1739
- _textParser . NextToken ( ) ;
1812
+ if ( _textParser . CurrentToken . Id == TokenId . Identifier )
1813
+ {
1814
+ parts . Add ( _textParser . CurrentToken . Text ) ;
1815
+ _textParser . NextToken ( ) ;
1816
+ }
1817
+ }
1740
1818
1741
- LastLambdaItName = ItName ;
1742
- var exp = ParseConditionalOperator ( ) ;
1819
+ var enumTypeAsString = string . Join ( "" , parts . Take ( parts . Count - 2 ) . ToArray ( ) ) ;
1820
+ var enumType = _typeFinder . FindTypeByName ( enumTypeAsString , null , true ) ;
1821
+ if ( enumType == null )
1822
+ {
1823
+ throw ParseError ( _textParser . CurrentToken . Pos , Res . EnumTypeNotFound , enumTypeAsString ) ;
1824
+ }
1743
1825
1744
- // Restore previous context and clear internals
1745
- _internals . Remove ( id ) ;
1746
- ItName = _previousItName ;
1826
+ string enumValueAsString = parts . LastOrDefault ( ) ;
1827
+ if ( enumValueAsString == null )
1828
+ {
1829
+ throw ParseError ( _textParser . CurrentToken . Pos , Res . EnumValueExpected ) ;
1830
+ }
1747
1831
1748
- return exp ;
1832
+ var enumValue = TypeHelper . ParseEnum ( enumValueAsString , enumType ) ;
1833
+ if ( enumValue == null )
1834
+ {
1835
+ throw ParseError ( _textParser . CurrentToken . Pos , Res . EnumValueNotDefined , enumValueAsString , enumTypeAsString ) ;
1749
1836
}
1750
1837
1751
- throw ParseError ( errorPos , Res . UnknownPropertyOrField , id , TypeHelper . GetTypeName ( type ) ) ;
1838
+ return Expression . Constant ( enumValue ) ;
1752
1839
}
1753
1840
1754
1841
Expression ParseEnumerable ( Expression instance , Type elementType , string methodName , int errorPos , Type type )
0 commit comments