Skip to content

Commit 9fc7479

Browse files
authored
Fix example 'ConsoleApp_netcore2.1_EF2.1.1' (#583)
* wip * fixes
1 parent b910b38 commit 9fc7479

File tree

9 files changed

+139
-52
lines changed

9 files changed

+139
-52
lines changed

.editorconfig

+73-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,78 @@ root = true
22

33
[*]
44
end_of_line = crlf
5-
insert_final_newline = true
5+
insert_final_newline = false
66
indent_style = space
77
indent_size = 4
8+
csharp_indent_labels = one_less_than_current
9+
csharp_using_directive_placement = outside_namespace:silent
10+
csharp_prefer_simple_using_statement = true:suggestion
11+
csharp_prefer_braces = true:silent
12+
csharp_style_namespace_declarations = block_scoped:silent
13+
csharp_style_expression_bodied_methods = false:silent
14+
csharp_style_expression_bodied_constructors = false:silent
15+
csharp_style_expression_bodied_operators = false:silent
16+
csharp_style_expression_bodied_properties = true:silent
17+
csharp_style_expression_bodied_indexers = true:silent
18+
csharp_style_expression_bodied_accessors = true:silent
19+
csharp_style_expression_bodied_lambdas = true:silent
20+
csharp_style_expression_bodied_local_functions = false:silent
21+
22+
[*.{cs,vb}]
23+
#### Naming styles ####
24+
25+
# Naming rules
26+
27+
dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
28+
dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
29+
dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
30+
31+
dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
32+
dotnet_naming_rule.types_should_be_pascal_case.symbols = types
33+
dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
34+
35+
dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
36+
dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
37+
dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
38+
39+
# Symbol specifications
40+
41+
dotnet_naming_symbols.interface.applicable_kinds = interface
42+
dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
43+
dotnet_naming_symbols.interface.required_modifiers =
44+
45+
dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
46+
dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
47+
dotnet_naming_symbols.types.required_modifiers =
48+
49+
dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
50+
dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
51+
dotnet_naming_symbols.non_field_members.required_modifiers =
52+
53+
# Naming styles
54+
55+
dotnet_naming_style.begins_with_i.required_prefix = I
56+
dotnet_naming_style.begins_with_i.required_suffix =
57+
dotnet_naming_style.begins_with_i.word_separator =
58+
dotnet_naming_style.begins_with_i.capitalization = pascal_case
59+
60+
dotnet_naming_style.pascal_case.required_prefix =
61+
dotnet_naming_style.pascal_case.required_suffix =
62+
dotnet_naming_style.pascal_case.word_separator =
63+
dotnet_naming_style.pascal_case.capitalization = pascal_case
64+
65+
dotnet_naming_style.pascal_case.required_prefix =
66+
dotnet_naming_style.pascal_case.required_suffix =
67+
dotnet_naming_style.pascal_case.word_separator =
68+
dotnet_naming_style.pascal_case.capitalization = pascal_case
69+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
70+
tab_width = 4
71+
dotnet_style_coalesce_expression = true:suggestion
72+
dotnet_style_null_propagation = true:suggestion
73+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
74+
dotnet_style_prefer_auto_properties = true:silent
75+
dotnet_style_object_initializer = true:suggestion
76+
dotnet_style_collection_initializer = true:suggestion
77+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
78+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
79+
dotnet_style_prefer_conditional_expression_over_return = true:silent

System.Linq.Dynamic.Core.sln

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{25E69107-C89E-4807-AA31-C49423F0F1E3}"
1111
ProjectSection(SolutionItems) = preProject
1212
.deployment = .deployment
13+
.editorconfig = .editorconfig
1314
azure-pipelines.yml = azure-pipelines.yml
1415
CHANGELOG.md = CHANGELOG.md
1516
Directory.Build.props = Directory.Build.props

src-console/ConsoleAppEF2.0.2_InMemory/Program.cs

+10-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Newtonsoft.Json;
44
using System;
55
using System.Collections.Generic;
6+
using System.IO;
67
using System.Linq;
78
using System.Linq.Dynamic.Core;
89
using System.Linq.Dynamic.Core.CustomTypeProviders;
@@ -27,14 +28,19 @@ class C : AbstractDynamicLinqCustomTypeProvider, IDynamicLinkCustomTypeProvider
2728
{
2829
public HashSet<Type> GetCustomTypes()
2930
{
30-
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
31+
// https://stackoverflow.com/a/2384679/255966
32+
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
33+
var loadedPaths = loadedAssemblies.Where(a => !a.IsDynamic).Select(a => a.Location).ToArray();
34+
35+
var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
36+
var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList();
3137

32-
var set = new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies))
38+
toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path))));
39+
40+
return new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(loadedAssemblies))
3341
{
3442
typeof(TestContext)
3543
};
36-
37-
return set;
3844
}
3945

4046
public Dictionary<Type, List<MethodInfo>> GetExtensionMethods()

src-console/ConsoleAppEF2.0/Program.cs

+11-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Linq.Dynamic.Core;
56
using System.Linq.Dynamic.Core.CustomTypeProviders;
67
using System.Reflection;
78
using System.Runtime.CompilerServices;
89
using ConsoleAppEF2.Database;
9-
using JetBrains.Annotations;
1010
using Microsoft.EntityFrameworkCore;
1111
using Newtonsoft.Json;
1212

@@ -18,13 +18,19 @@ class C : AbstractDynamicLinqCustomTypeProvider, IDynamicLinkCustomTypeProvider
1818
{
1919
public HashSet<Type> GetCustomTypes()
2020
{
21-
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
21+
// https://stackoverflow.com/a/2384679/255966
22+
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
23+
var loadedPaths = loadedAssemblies.Where(a => !a.IsDynamic).Select(a => a.Location).ToArray();
2224

23-
var set = new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies));
25+
var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
26+
var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList();
2427

25-
set.Add(typeof(TestContext));
28+
toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path))));
2629

27-
return set;
30+
return new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(loadedAssemblies))
31+
{
32+
typeof(TestContext)
33+
};
2834
}
2935

3036
public Dictionary<Type, List<MethodInfo>> GetExtensionMethods()

src-console/ConsoleAppEF2.1.1/Program.cs

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.IO;
34
using System.Linq;
45
using System.Linq.Dynamic.Core;
56
using System.Linq.Dynamic.Core.CustomTypeProviders;
67
using System.Linq.Expressions;
78
using System.Reflection;
89
using System.Runtime.CompilerServices;
910
using ConsoleAppEF2.Database;
10-
using JetBrains.Annotations;
1111
using Microsoft.EntityFrameworkCore;
1212
using Newtonsoft.Json;
1313

@@ -19,13 +19,19 @@ class C : AbstractDynamicLinqCustomTypeProvider, IDynamicLinkCustomTypeProvider
1919
{
2020
public HashSet<Type> GetCustomTypes()
2121
{
22-
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
22+
// https://stackoverflow.com/a/2384679/255966
23+
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
24+
var loadedPaths = loadedAssemblies.Where(a => !a.IsDynamic).Select(a => a.Location).ToArray();
2325

24-
var set = new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(assemblies));
26+
var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
27+
var toLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase)).ToList();
2528

26-
set.Add(typeof(TestContext));
29+
toLoad.ForEach(path => loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path))));
2730

28-
return set;
31+
return new HashSet<Type>(FindTypesMarkedWithDynamicLinqTypeAttribute(loadedAssemblies))
32+
{
33+
typeof(TestContext)
34+
};
2935
}
3036

3137
public Dictionary<Type, List<MethodInfo>> GetExtensionMethods()
@@ -103,6 +109,7 @@ static void Main(string[] args)
103109
Console.WriteLine("all {0}", JsonConvert.SerializeObject(all, Formatting.Indented));
104110

105111
var config = ParsingConfig.DefaultEFCore21;
112+
//config.ResolveTypesBySimpleName = true;
106113
config.CustomTypeProvider = new C();
107114

108115
var context = new TestContext();

src/System.Linq.Dynamic.Core/CustomTypeProviders/AbstractDynamicLinqCustomTypeProvider.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ protected Type ResolveTypeBySimpleName([NotNull] IEnumerable<Assembly> assemblie
6060

6161
foreach (var assembly in assemblies)
6262
{
63-
var fullnames = assembly.GetTypes().Select(t => t.FullName).Distinct();
64-
var firstMatchingFullname = fullnames.FirstOrDefault(fn => fn.EndsWith($".{simpleTypeName}"));
63+
var fullNames = assembly.GetTypes().Select(t => t.FullName).Distinct();
64+
var firstMatchingFullname = fullNames.FirstOrDefault(fn => fn.EndsWith($".{simpleTypeName}"));
6565

6666
if (firstMatchingFullname != null)
6767
{
@@ -128,8 +128,10 @@ protected IEnumerable<Type> GetAssemblyTypesWithDynamicLinqTypeAttribute([NotNul
128128

129129
try
130130
{
131-
definedTypes = assembly.GetExportedTypes()
132-
.Where(t => t.IsDefined(typeof(DynamicLinqTypeAttribute), false)).ToArray();
131+
definedTypes = assembly
132+
.GetExportedTypes()
133+
.Where(t => t.IsDefined(typeof(DynamicLinqTypeAttribute), false))
134+
.ToArray();
133135
}
134136
catch (ReflectionTypeLoadException reflectionTypeLoadException)
135137
{

src/System.Linq.Dynamic.Core/CustomTypeProviders/DefaultDynamicLinqCustomTypeProvider.cs

+5-3
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,14 @@ private Dictionary<Type, List<MethodInfo>> GetExtensionMethodsInternal()
9191
{
9292
var types = GetCustomTypes();
9393

94-
List<Tuple<Type, MethodInfo>> list = new List<Tuple<Type, MethodInfo>>();
94+
var list = new List<Tuple<Type, MethodInfo>>();
9595

9696
foreach (var type in types)
9797
{
98-
var extensionMethods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
99-
.Where(x => x.IsDefined(typeof(ExtensionAttribute), false)).ToList();
98+
var extensionMethods = type
99+
.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
100+
.Where(x => x.IsDefined(typeof(ExtensionAttribute), false))
101+
.ToList();
100102

101103
extensionMethods.ForEach(x => list.Add(new Tuple<Type, MethodInfo>(x.GetParameters()[0].ParameterType, x)));
102104
}
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,39 @@
1-
using System.Reflection;
1+
using System.IO;
2+
using System.Reflection;
23

34
namespace System.Linq.Dynamic.Core
45
{
56
internal class DefaultAssemblyHelper : IAssemblyHelper
67
{
7-
#if DOTNET5_4
88
public Assembly[] GetAssemblies()
99
{
10-
var assemblyNames = Microsoft.Extensions.PlatformAbstractions.PlatformServices.Default.LibraryManager.GetLibraries()
11-
.SelectMany(lib => lib.Assemblies)
12-
.Distinct()
13-
.ToArray();
10+
#if WINDOWS_APP || UAP10_0 || NETSTANDARD || WPSL
11+
throw new NotSupportedException();
12+
#elif NET35
13+
14+
return AppDomain.CurrentDomain.GetAssemblies();
15+
#else
16+
// https://stackoverflow.com/a/2384679/255966
17+
var loadedAssemblies = AppDomain.CurrentDomain.GetAssemblies().ToList();
18+
var loadedPaths = loadedAssemblies.Where(a => !a.IsDynamic).Select(a => a.Location).ToArray();
19+
20+
var referencedPaths = Directory.GetFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll");
21+
var pathsToLoad = referencedPaths.Where(r => !loadedPaths.Contains(r, StringComparer.InvariantCultureIgnoreCase));
1422

15-
var assemblies = new System.Collections.Generic.List<Assembly>();
16-
foreach (var assembly in assemblyNames.Select(Assembly.Load))
23+
foreach (var path in pathsToLoad)
1724
{
1825
try
1926
{
20-
var dummy = assembly.DefinedTypes.ToArray();
21-
// just load all types and skip this assembly of one or more types cannot be resolved
22-
assemblies.Add(assembly);
27+
loadedAssemblies.Add(AppDomain.CurrentDomain.Load(AssemblyName.GetAssemblyName(path)));
2328
}
24-
catch (Exception)
29+
catch
2530
{
31+
// Ignore
2632
}
2733
}
2834

29-
return assemblies.ToArray();
30-
}
31-
32-
#elif WINDOWS_APP || UAP10_0 || NETSTANDARD || WPSL
33-
public Assembly[] GetAssemblies()
34-
{
35-
throw new NotSupportedException();
36-
}
37-
#else
38-
public Assembly[] GetAssemblies()
39-
{
40-
#if NETCORE1_1
41-
return AppDomain.NetCoreApp.AppDomain.CurrentDomain.GetAssemblies(thisType).ToArray();
42-
#else
43-
return AppDomain.CurrentDomain.GetAssemblies();
35+
return loadedAssemblies.ToArray();
4436
#endif
4537
}
46-
#endif
47-
}
4838
}
39+
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ private Expression ParseAsEnum(string id)
17531753
}
17541754
}
17551755

1756-
var enumTypeAsString = string.Join("", parts.Take(parts.Count - 2).ToArray());
1756+
var enumTypeAsString = string.Concat(parts.Take(parts.Count - 2).ToArray());
17571757
var enumType = _typeFinder.FindTypeByName(enumTypeAsString, null, true);
17581758
if (enumType == null)
17591759
{

0 commit comments

Comments
 (0)