diff --git a/src/System.Linq.Dynamic.Core/ExpressionParser.cs b/src/System.Linq.Dynamic.Core/ExpressionParser.cs index 282a3bb0..9c4471eb 100644 --- a/src/System.Linq.Dynamic.Core/ExpressionParser.cs +++ b/src/System.Linq.Dynamic.Core/ExpressionParser.cs @@ -205,32 +205,29 @@ interface IEnumerableSignatures { "bool", typeof(bool) }, { "float", typeof(float) }, }; - static readonly HashSet _predefinedTypes = new HashSet() { - typeof(object), - typeof(bool), - typeof(char), - typeof(string), - typeof(sbyte), - typeof(byte), - typeof(short), - typeof(ushort), - typeof(int), - typeof(uint), - typeof(long), - typeof(ulong), - typeof(float), - typeof(double), - typeof(decimal), - typeof(DateTime), - typeof(DateTimeOffset), - typeof(TimeSpan), - typeof(Guid), - typeof(Math), - typeof(Convert), - typeof(Uri), -#if !(NET35 || SILVERLIGHT || NETFX_CORE || DNXCORE50 || DOTNET5_4 || NETSTANDARD) - typeof(Data.Objects.EntityFunctions) -#endif + static readonly Dictionary _predefinedTypes = new Dictionary() { + { typeof(object), 0 }, + { typeof(bool), 0 }, + { typeof(char), 0 }, + { typeof(string), 0 }, + { typeof(sbyte), 0 }, + { typeof(byte), 0 }, + { typeof(short), 0 }, + { typeof(ushort), 0 }, + { typeof(int), 0 }, + { typeof(uint), 0 }, + { typeof(long), 0 }, + { typeof(ulong), 0 }, + { typeof(float), 0 }, + { typeof(double), 0 }, + { typeof(decimal), 0 }, + { typeof(DateTime), 0 }, + { typeof(DateTimeOffset), 0 }, + { typeof(TimeSpan), 0 }, + { typeof(Guid), 0 }, + { typeof(Math), 0 }, + { typeof(Convert), 0 }, + { typeof(Uri), 0 } }; // These aliases are supposed to simply the where clause and make it more human readable @@ -279,6 +276,43 @@ interface IEnumerableSignatures char _ch; Token _token; + static ExpressionParser() + { +#if !(NET35 || SILVERLIGHT || NETFX_CORE || DNXCORE50 || DOTNET5_4 || NETSTANDARD) + try + { + //System.Data.Entity is always here, so overwrite short name of it with EntityFramework if EntityFramework is found. + Type efType; + //EF5(or 4.x??), System.Data.Objects.DataClasses.EdmFunctionAttribute + //There is also an System.Data.Entity, Version=3.5.0.0, but no Functions. + efType = Type.GetType("System.Data.Objects.EntityFunctions, System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + if (efType != null) + _predefinedTypes.Add(efType, 1); + efType = Type.GetType("System.Data.Objects.SqlClient.SqlFunctions, System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + if (efType != null) + _predefinedTypes.Add(efType, 1); + efType = Type.GetType("System.Data.Objects.SqlClient.SqlSpatialFunctions, System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + if (efType != null) + _predefinedTypes.Add(efType, 1); + + //EF6,System.Data.Entity.DbFunctionAttribute + efType = Type.GetType("System.Data.Entity.Core.Objects.EntityFunctions, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + if (efType != null) + _predefinedTypes.Add(efType, 2); + efType = Type.GetType("System.Data.Entity.DbFunctions, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + if (efType != null) + _predefinedTypes.Add(efType, 2); + efType = Type.GetType("System.Data.Entity.SqlServer.SqlFunctions, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + if (efType != null) + _predefinedTypes.Add(efType, 2); + efType = Type.GetType("System.Data.Entity.SqlServer.SqlSpatialFunctions, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); + if (efType != null) + _predefinedTypes.Add(efType, 2); + } + catch { } +#endif + } + public ExpressionParser(ParameterExpression[] parameters, string expression, object[] values) { if (_keywords == null) _keywords = CreateKeywords(); @@ -1326,7 +1360,7 @@ Expression ParseElementAccess(Expression expr) static bool IsPredefinedType(Type type) { - if (_predefinedTypes.Contains(type)) return true; + if (_predefinedTypes.ContainsKey(type)) return true; if (GlobalConfig.CustomTypeProvider.GetCustomTypes().Contains(type)) return true; return false; @@ -2468,9 +2502,17 @@ static Dictionary CreateKeywords() d.Add(KEYWORD_IIF, KEYWORD_IIF); d.Add(KEYWORD_NEW, KEYWORD_NEW); - foreach (Type type in _predefinedTypes) d.Add(type.Name, type); + foreach (Type type in _predefinedTypes.OrderBy(kvp => kvp.Value).Select(kvp => kvp.Key)) + { + d[type.FullName] = type; + d[type.Name] = type; + } foreach (KeyValuePair pair in _predefinedTypesShorthands) d.Add(pair.Key, pair.Value); - foreach (Type type in GlobalConfig.CustomTypeProvider.GetCustomTypes()) d.Add(type.Name, type); + foreach (Type type in GlobalConfig.CustomTypeProvider.GetCustomTypes()) + { + d[type.FullName] = type; + d[type.Name] = type; + } return d; } diff --git a/src/System.Linq.Dynamic.Core/GroupResult.cs b/src/System.Linq.Dynamic.Core/GroupResult.cs index 50385769..b2d37b65 100644 --- a/src/System.Linq.Dynamic.Core/GroupResult.cs +++ b/src/System.Linq.Dynamic.Core/GroupResult.cs @@ -38,7 +38,7 @@ public class GroupResult /// public override string ToString() { - return string.Format(CultureInfo.CurrentCulture, "{0} ({1})", Key, Count); + return string.Format(CultureInfo.CurrentCulture, "{0} ({1})", ((object)Key).ToString(), Count); } } } diff --git a/src/System.Linq.Dynamic.Core/project.json b/src/System.Linq.Dynamic.Core/project.json index 0bbfd86f..1a9f2627 100644 --- a/src/System.Linq.Dynamic.Core/project.json +++ b/src/System.Linq.Dynamic.Core/project.json @@ -13,137 +13,69 @@ "compilationOptions": { }, + "dependencies": { + "JetBrains.Annotations": { + "version": "10.1.4", + "type": "build" + } + }, + "frameworks": { "net35": { "frameworkAssemblies": { }, "dependencies": { - "JetBrains.Annotations": "10.1.4", "NetLegacySupport.ConcurrentDictionary": "1.1.0" } }, "net40": { - "dependencies": { - "JetBrains.Annotations": "10.1.4" - }, "frameworkAssemblies": { - "System.Data.Entity": "" } }, "net45": { - "dependencies": { - "JetBrains.Annotations": "10.1.4" - }, "frameworkAssemblies": { - "System.Data.Entity": "" } }, "net451": { - "dependencies": { - "JetBrains.Annotations": "10.1.4" - }, "frameworkAssemblies": { - "System.Data.Entity": "" } }, "net452": { - "dependencies": { - "JetBrains.Annotations": "10.1.4" - }, "frameworkAssemblies": { - "System.Data.Entity": "" } }, "net461": { - "dependencies": { - "JetBrains.Annotations": "10.1.4" - }, "frameworkAssemblies": { - "System.Data.Entity": "" } }, "dnx451": { - "dependencies": { - "JetBrains.Annotations": "10.1.4" - }, "frameworkAssemblies": { - "System.Data.Entity": "" } }, "dnx452": { - "dependencies": { - "JetBrains.Annotations": "10.1.4" - }, "frameworkAssemblies": { - "System.Data.Entity": "" } }, "dnxcore5": { "dependencies": { - "JetBrains.Annotations": "10.1.4", - - "Microsoft.CSharp": "4.0.1-beta-*", - - "System.Collections.Concurrent": "4.0.11-beta-*", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final", - - "System.Runtime.Extensions": "4.0.11-beta-*", - "System.Runtime.InteropServices": "4.0.21-beta-*", - "System.Runtime.Loader": "4.0.0-beta-*", - - "System.Runtime.Serialization.Primitives": "4.1.0-beta-*", - "System.Runtime.Serialization.Xml": "4.1.0-beta-*", - - "System.Reflection.Primitives": "4.0.1-beta-*", - "System.Reflection.TypeExtensions": "4.1.0-beta-*", - "System.Reflection.Emit": "4.0.1-beta-*", - - "System.Linq": "4.0.1-beta-*", - "System.Linq.Expressions": "4.0.11-beta-*", - "System.Linq.Queryable": "4.0.1-beta-*", - - "System.Globalization": "4.0.11-beta-*", - - "System.Diagnostics.Debug": "4.0.11-beta-*", - "System.Diagnostics.Tools": "4.0.1-beta-*", - "System.Diagnostics.Tracing": "4.0.21-beta-*", - - "System.Threading": "4.0.11-beta-*" + "System.Collections.Concurrent": "4.0.11-*", + "System.Dynamic.Runtime": "4.0.11-*", + "System.Reflection.Emit": "4.0.1-*", + "System.Reflection.TypeExtensions": "4.1.0-*", + "System.Linq.Expressions": "4.0.11-*", + "System.Linq.Queryable": "4.0.1-*" } }, "dotnet54": { "dependencies": { - "JetBrains.Annotations": "10.1.4", - - "Microsoft.CSharp": "4.0.1-beta-*", - - "System.Collections.Concurrent": "4.0.11-beta-*", - "Microsoft.Extensions.PlatformAbstractions": "1.0.0-rc1-final", - - "System.Runtime.Extensions": "4.0.11-beta-*", - "System.Runtime.InteropServices": "4.0.21-beta-*", - "System.Runtime.Loader": "4.0.0-beta-*", - - "System.Runtime.Serialization.Primitives": "4.1.0-beta-*", - "System.Runtime.Serialization.Xml": "4.1.0-beta-*", - - "System.Reflection.Primitives": "4.0.1-beta-*", - "System.Reflection.TypeExtensions": "4.1.0-beta-*", - "System.Reflection.Emit": "4.0.1-beta-*", - - "System.Linq": "4.0.1-beta-*", - "System.Linq.Expressions": "4.0.11-beta-*", - "System.Linq.Queryable": "4.0.1-beta-*", - - "System.Globalization": "4.0.11-beta-*", - - "System.Diagnostics.Debug": "4.0.11-beta-*", - "System.Diagnostics.Tools": "4.0.1-beta-*", - "System.Diagnostics.Tracing": "4.0.21-beta-*", - - "System.Threading": "4.0.11-beta-*" + "System.Collections.Concurrent": "4.0.11-*", + "System.Dynamic.Runtime": "4.0.11-*", + "System.Reflection.Emit": "4.0.1-*", + "System.Reflection.TypeExtensions": "4.1.0-*", + "System.Linq.Expressions": "4.0.11-*", + "System.Linq.Queryable": "4.0.1-*" } }, "sl5": { @@ -151,7 +83,6 @@ "define": [ "SILVERLIGHT" ] }, "dependencies": { - "JetBrains.Annotations": "10.1.4", "Portable.ConcurrentDictionary": "1.0.1" }, "frameworkAssemblies": { diff --git a/web/DynamicLinqWebDocs/DynamicLinqWebDocs.csproj b/web/DynamicLinqWebDocs/DynamicLinqWebDocs.csproj index 5d320fc0..09feffbb 100644 --- a/web/DynamicLinqWebDocs/DynamicLinqWebDocs.csproj +++ b/web/DynamicLinqWebDocs/DynamicLinqWebDocs.csproj @@ -43,18 +43,18 @@ False - ..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll + ..\..\packages\Antlr.3.5.0.2\lib\Antlr3.Runtime.dll - ..\packages\MarkdownSharp.1.13.0.0\lib\35\MarkdownSharp.dll + ..\..\packages\MarkdownSharp.1.13.0.0\lib\35\MarkdownSharp.dll - ..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll + ..\..\packages\Newtonsoft.Json.8.0.3\lib\net45\Newtonsoft.Json.dll True - ..\packages\SimpleMvcSitemap.2.3.1\lib\net45\SimpleMvcSitemap.dll + ..\..\packages\SimpleMvcSitemap.2.3.1\lib\net45\SimpleMvcSitemap.dll True @@ -68,34 +68,34 @@ - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.Helpers.dll True - ..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll + ..\..\packages\Microsoft.AspNet.Mvc.5.2.3\lib\net45\System.Web.Mvc.dll True False - ..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll + ..\..\packages\Microsoft.AspNet.Web.Optimization.1.1.3\lib\net40\System.Web.Optimization.dll - ..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll + ..\..\packages\Microsoft.AspNet.Razor.3.2.3\lib\net45\System.Web.Razor.dll True - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.dll True - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Deployment.dll True - ..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll + ..\..\packages\Microsoft.AspNet.WebPages.3.2.3\lib\net45\System.Web.WebPages.Razor.dll True @@ -104,7 +104,7 @@ True - ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll + ..\..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll @@ -113,7 +113,7 @@ False - ..\packages\WebGrease.1.6.0\lib\WebGrease.dll + ..\..\packages\WebGrease.1.6.0\lib\WebGrease.dll