Skip to content

Commit da82150

Browse files
committed
.
1 parent 1fd182c commit da82150

File tree

4 files changed

+26
-26
lines changed

4 files changed

+26
-26
lines changed

src/Microsoft.EntityFrameworkCore.DynamicLinq.EFCore3/Microsoft.EntityFrameworkCore.DynamicLinq.EFCore3.csproj

-3
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242

4343
<ItemGroup>
4444
<PackageReference Include="JetBrains.Annotations" Version="2022.3.1" PrivateAssets="All" />
45-
</ItemGroup>
46-
47-
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0'">
4845
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
4946
</ItemGroup>
5047

src/System.Linq.Dynamic.Core/Parser/PredefinedTypesHelper.cs

+11-7
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@ namespace System.Linq.Dynamic.Core.Parser;
66

77
internal static class PredefinedTypesHelper
88
{
9-
private const string PublicKeyToken = "974e7e1b462f3693";
10-
private static readonly string Version = Text.RegularExpressions.Regex.Match(typeof(PredefinedTypesHelper).AssemblyQualifiedName!, @"\d+\.\d+\.\d+\.\d+").ToString();
11-
129
// These shorthands have different name than actual type and therefore not recognized by default from the PredefinedTypes.
1310
public static readonly IDictionary<string, Type> PredefinedTypesShorthands = new Dictionary<string, Type>
1411
{
@@ -29,7 +26,7 @@ internal static class PredefinedTypesHelper
2926
{ "ushort", typeof(ushort) }
3027
};
3128

32-
public static readonly IDictionary<Type, int> PredefinedTypes = new ConcurrentDictionary<Type, int>(new Dictionary<Type, int>
29+
public static readonly IDictionary<Type, int> PredefinedTypes = new ConcurrentDictionary<Type, int>(new Dictionary<Type, int>
3330
{
3431
{ typeof(object), 0 },
3532
{ typeof(bool), 0 },
@@ -62,6 +59,9 @@ internal static class PredefinedTypesHelper
6259

6360
static PredefinedTypesHelper()
6461
{
62+
// Only add these types for full .NET Framework and .NETStandard 2.1
63+
// And only if the EntityFramework.DynamicLinq is available.
64+
#if NET452_OR_GREATER || NETSTANDARD2_1
6565
if (Type.GetType("EntityFramework.DynamicLinq.EFType, EntityFramework.DynamicLinq") != null)
6666
{
6767
TryAdd("System.Data.Objects.EntityFunctions, System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", 1);
@@ -73,11 +73,16 @@ static PredefinedTypesHelper()
7373
TryAdd("System.Data.Entity.SqlServer.SqlFunctions, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", 2);
7474
TryAdd("System.Data.Entity.SqlServer.SqlSpatialFunctions, EntityFramework.SqlServer, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089", 2);
7575
}
76+
#endif
7677

77-
if (Type.GetType($"Microsoft.EntityFrameworkCore.DynamicLinq.EFType, Microsoft.EntityFrameworkCore.DynamicLinq, Version={Version}, Culture=neutral, PublicKeyToken={PublicKeyToken}") != null)
78+
#if NETSTANDARD2_0_OR_GREATER || NET5_0_OR_GREATER
79+
const string publicKeyToken = "974e7e1b462f3693";
80+
var version = Text.RegularExpressions.Regex.Match(typeof(PredefinedTypesHelper).AssemblyQualifiedName!, @"\d+\.\d+\.\d+\.\d+").ToString();
81+
if (Type.GetType($"Microsoft.EntityFrameworkCore.DynamicLinq.EFType, Microsoft.EntityFrameworkCore.DynamicLinq, Version={version}, Culture=neutral, PublicKeyToken={publicKeyToken}") != null)
7882
{
79-
TryAdd($"Microsoft.EntityFrameworkCore.DynamicLinq.DynamicFunctions, Microsoft.EntityFrameworkCore.DynamicLinq, Version={Version}, Culture=neutral, PublicKeyToken={PublicKeyToken}", 3);
83+
TryAdd($"Microsoft.EntityFrameworkCore.DynamicLinq.DynamicFunctions, Microsoft.EntityFrameworkCore.DynamicLinq, Version={version}, Culture=neutral, PublicKeyToken={publicKeyToken}", 3);
8084
}
85+
#endif
8186
}
8287

8388
private static void TryAdd(string typeName, int x)
@@ -107,7 +112,6 @@ public static bool IsPredefinedType(ParsingConfig config, Type type)
107112
return true;
108113
}
109114

110-
// ReSharper disable once ConditionIsAlwaysTrueOrFalseAccordingToNullableAPIContract
111115
return config.CustomTypeProvider != null &&
112116
(config.CustomTypeProvider.GetCustomTypes().Contains(type) || config.CustomTypeProvider.GetCustomTypes().Contains(nonNullableType));
113117
}

src/System.Linq.Dynamic.Core/Parser/SupportedMethods/MethodFinder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public int FindMethod(Type? type, string methodName, bool staticAccess, ref Expr
113113
}
114114
#endif
115115

116-
if (instance != null)
116+
if (instance != null && _parsingConfig.CustomTypeProvider != null)
117117
{
118118
// Try to solve with registered extension methods from this type and all base types
119119
var methods = new List<MethodInfo>();

src/System.Linq.Dynamic.Core/ParsingConfig.cs

+14-15
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@ public class ParsingConfig
4949
/// <summary>
5050
/// Gets or sets the <see cref="IDynamicLinkCustomTypeProvider"/>.
5151
/// </summary>
52-
public IDynamicLinkCustomTypeProvider CustomTypeProvider
52+
public IDynamicLinkCustomTypeProvider? CustomTypeProvider
5353
{
5454
get
5555
{
5656
#if !(WINDOWS_APP || UAP10_0 || NETSTANDARD)
5757
// Only use DefaultDynamicLinqCustomTypeProvider for full .NET Framework and .NET Core App 2.x and higher.
5858
return _customTypeProvider ??= new DefaultDynamicLinqCustomTypeProvider(this);
5959
#else
60-
return _customTypeProvider;
60+
return _customTypeProvider;
6161
#endif
6262
}
6363

@@ -141,21 +141,21 @@ public IQueryableAnalyzer QueryableAnalyzer
141141
///
142142
/// Default value is <c>false</c>.
143143
/// </summary>
144-
public bool UseParameterizedNamesInDynamicQuery { get; set; } = false;
144+
public bool UseParameterizedNamesInDynamicQuery { get; set; }
145145

146146
/// <summary>
147147
/// Allows the New() keyword to evaluate any available Type.
148148
///
149149
/// Default value is <c>false</c>.
150150
/// </summary>
151-
public bool AllowNewToEvaluateAnyType { get; set; } = false;
151+
public bool AllowNewToEvaluateAnyType { get; set; }
152152

153153
/// <summary>
154-
/// Renames the (Typed)ParameterExpression empty Name to a the correct supplied name from `it`.
154+
/// Renames the (Typed)ParameterExpression empty Name to the correct supplied name from `it`.
155155
///
156156
/// Default value is <c>false</c>.
157157
/// </summary>
158-
public bool RenameParameterExpression { get; set; } = false;
158+
public bool RenameParameterExpression { get; set; }
159159

160160
/// <summary>
161161
/// Prevents any System.Linq.Expressions.ParameterExpression.Name value from being empty by substituting a random 16 character word.
@@ -165,13 +165,12 @@ public IQueryableAnalyzer QueryableAnalyzer
165165
public bool RenameEmptyParameterExpressionNames { get; set; }
166166

167167
/// <summary>
168-
/// By default, when a member is not found in a type and the type has a string based index accessor it will be parsed as an index accessor. Use
169-
/// this flag to disable this behaviour and have parsing fail when parsing an expression
170-
/// where a member access on a non existing member happens.
168+
/// By default, when a member is not found in a type and the type has a string based index accessor it will be parsed as an index accessor.
169+
/// Use this flag to disable this behaviour and have parsing fail when parsing an expression where a member access on a non-existing member happens.
171170
///
172171
/// Default value is <c>false</c>.
173172
/// </summary>
174-
public bool DisableMemberAccessToIndexAccessorFallback { get; set; } = false;
173+
public bool DisableMemberAccessToIndexAccessorFallback { get; set; }
175174

176175
/// <summary>
177176
/// By default, finding types by a simple name is not supported.
@@ -180,7 +179,7 @@ public IQueryableAnalyzer QueryableAnalyzer
180179
///
181180
/// Default value is <c>false</c>.
182181
/// </summary>
183-
public bool ResolveTypesBySimpleName { get; set; } = false;
182+
public bool ResolveTypesBySimpleName { get; set; }
184183

185184
/// <summary>
186185
/// Support enumeration-types from the System namespace in mscorlib. An example could be "StringComparison".
@@ -195,7 +194,7 @@ public IQueryableAnalyzer QueryableAnalyzer
195194
///
196195
/// Default value is <c>false</c>.
197196
/// </summary>
198-
public bool DateTimeIsParsedAsUTC { get; set; } = false;
197+
public bool DateTimeIsParsedAsUTC { get; set; }
199198

200199
/// <summary>
201200
/// The number parsing culture.
@@ -214,7 +213,7 @@ public IQueryableAnalyzer QueryableAnalyzer
214213
///
215214
/// Default value is <c>false</c>.
216215
/// </summary>
217-
public bool NullPropagatingUseDefaultValueForNonNullableValueTypes { get; set; } = false;
216+
public bool NullPropagatingUseDefaultValueForNonNullableValueTypes { get; set; }
218217

219218
/// <summary>
220219
/// Support casting to a full qualified type using a string (double-quoted value).
@@ -240,14 +239,14 @@ public IQueryableAnalyzer QueryableAnalyzer
240239
///
241240
/// Default value is <c>false</c>.
242241
/// </summary>
243-
public bool SupportDotInPropertyNames { get; set; } = false;
242+
public bool SupportDotInPropertyNames { get; set; }
244243

245244
/// <summary>
246245
/// Disallows the New() keyword to be used to construct a class.
247246
///
248247
/// Default value is <c>false</c>.
249248
/// </summary>
250-
public bool DisallowNewKeyword { get; set; } = false;
249+
public bool DisallowNewKeyword { get; set; }
251250

252251
/// <summary>
253252
/// Caches constant expressions to enhance performance. Periodic cleanup is performed to manage cache size, governed by this configuration.

0 commit comments

Comments
 (0)