Skip to content

Commit 0030512

Browse files
committed
various refactorings:
internalised/privatised implementation details expanded parameter types made fields readonly converted simple delegates to expressions converted conditionals to LINQ calls converted for..each list add to AddRange() removed redundant code whitespace fixes added R# settings
1 parent d48ccc7 commit 0030512

File tree

6 files changed

+25
-27
lines changed

6 files changed

+25
-27
lines changed

ScriptCs.sln.DotSettings

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="_" Suffix="" Style="aaBb" /&gt;</s:String></wpf:ResourceDictionary>

src/ScriptCs.Contracts/IAppDomainAssemblyResolver.cs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ namespace ScriptCs.Contracts
44
{
55
public interface IAppDomainAssemblyResolver
66
{
7-
void AddAssemblyPaths(IEnumerable<string> assemblyPaths);
87
void Initialize();
98
}
109
}

src/ScriptCs.Core/AppDomainAssemblyResolver.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class AppDomainAssemblyResolver : IAppDomainAssemblyResolver
1313
private readonly IFileSystem _fileSystem;
1414
private readonly IAssemblyResolver _resolver;
1515
private readonly IAssemblyUtility _assemblyUtility;
16-
private IDictionary<string, AssemblyInfo> _assemblyInfoMap;
16+
private readonly IDictionary<string, AssemblyInfo> _assemblyInfoMap;
1717

1818
public AppDomainAssemblyResolver(
1919
ILog logger,

src/ScriptCs.Core/AssemblyResolver.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,15 @@
22
using System.Collections.Generic;
33
using System.IO;
44
using System.Linq;
5-
using System.Reflection.Emit;
65
using Common.Logging;
7-
86
using ScriptCs.Contracts;
97

108
namespace ScriptCs
119
{
1210
public class AssemblyResolver : IAssemblyResolver
1311
{
1412
private readonly Dictionary<string, List<string>> _assemblyPathCache = new Dictionary<string, List<string>>();
15-
13+
1614
private readonly IFileSystem _fileSystem;
1715

1816
private readonly IPackageAssemblyResolver _packageAssemblyResolver;
@@ -62,7 +60,7 @@ public IEnumerable<string> GetAssemblyPaths(string path, bool binariesOnly = fal
6260
return assemblies;
6361
}
6462

65-
public IEnumerable<string> GetBinAssemblyPaths(string path)
63+
private IEnumerable<string> GetBinAssemblyPaths(string path)
6664
{
6765
var binFolder = Path.Combine(path, _fileSystem.BinFolder);
6866
if (!_fileSystem.DirectoryExists(binFolder))

src/ScriptCs.Hosting/ModuleLoader.cs

+19-20
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
using System.IO;
66
using System.Linq;
77
using System.Reflection;
8-
using System.Runtime.CompilerServices;
9-
using System.Runtime.InteropServices;
108
using Common.Logging;
119
using ScriptCs.Contracts;
1210

@@ -23,8 +21,8 @@ public class ModuleLoader : IModuleLoader
2321

2422
[ImportingConstructor]
2523
public ModuleLoader(IAssemblyResolver resolver, ILog logger, IFileSystem fileSystem, IAssemblyUtility assemblyUtility) :
26-
this(resolver, logger, null, null, fileSystem, assemblyUtility )
27-
{
24+
this(resolver, logger, null, null, fileSystem, assemblyUtility)
25+
{
2826
}
2927

3028
public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, AggregateCatalog> addToCatalog, Func<CompositionContainer, IEnumerable<Lazy<IModule, IModuleMetadata>>> getLazyModules, IFileSystem fileSystem, IAssemblyUtility assemblyUtility)
@@ -41,7 +39,7 @@ public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, Ag
4139
var assemblyCatalog = new AssemblyCatalog(assembly);
4240
catalog.Catalogs.Add(assemblyCatalog);
4341
}
44-
catch(Exception exception)
42+
catch (Exception exception)
4543
{
4644
logger.DebugFormat("Module Loader exception: {0}", exception.Message);
4745
}
@@ -52,11 +50,9 @@ public ModuleLoader(IAssemblyResolver resolver, ILog logger, Action<Assembly, Ag
5250

5351
if (getLazyModules == null)
5452
{
55-
getLazyModules = (container) =>
56-
{
57-
return container.GetExports<IModule, IModuleMetadata>();
58-
};
53+
getLazyModules = container => container.GetExports<IModule, IModuleMetadata>();
5954
}
55+
6056
_getLazyModules = getLazyModules;
6157
_fileSystem = fileSystem;
6258
_assemblyUtility = assemblyUtility;
@@ -78,13 +74,17 @@ public void Load(IModuleConfiguration config, string[] modulePackagesPaths, stri
7874
InitializeModules(config, extension, moduleNames, lazyModules);
7975
}
8076

81-
private void InitializeModules(IModuleConfiguration config, string extension, string[] moduleNames,
77+
private void InitializeModules(
78+
IModuleConfiguration config,
79+
string extension,
80+
IEnumerable<string> moduleNames,
8281
IEnumerable<Lazy<IModule, IModuleMetadata>> lazyModules)
8382
{
8483
var modules = lazyModules
8584
.Where(m => moduleNames.Contains(m.Metadata.Name) ||
8685
(extension != null && m.Metadata.Extensions != null &&
87-
(m.Metadata.Extensions.Split(',').Contains(extension))) || m.Metadata.Autoload == true)
86+
(m.Metadata.Extensions.Split(',').Contains(extension))) ||
87+
m.Metadata.Autoload)
8888
.Select(m => m.Value);
8989

9090
_logger.Debug("Initializing modules");
@@ -98,7 +98,7 @@ private void InitializeModules(IModuleConfiguration config, string extension, st
9898
_logger.Debug("Modules initialized");
9999
}
100100

101-
private AggregateCatalog CreateAggregateCatalog(List<string> paths)
101+
private AggregateCatalog CreateAggregateCatalog(IEnumerable<string> paths)
102102
{
103103
var catalog = new AggregateCatalog();
104104
foreach (var path in paths)
@@ -127,27 +127,24 @@ private AggregateCatalog CreateAggregateCatalog(List<string> paths)
127127
return catalog;
128128
}
129129

130-
private void AddPaths(string[] modulePackagesPaths, string hostBin, List<string> paths)
130+
private void AddPaths(IEnumerable<string> modulePackagesPaths, string hostBin, List<string> paths)
131131
{
132-
foreach (var modulePackagesPath in modulePackagesPaths)
132+
foreach (var modulePaths in modulePackagesPaths
133+
.Select(modulePackagesPath => _resolver.GetAssemblyPaths(modulePackagesPath, true)))
133134
{
134-
var modulePaths = _resolver.GetAssemblyPaths(modulePackagesPath, true);
135135
paths.AddRange(modulePaths);
136136
}
137137

138138
if (hostBin != null)
139139
{
140140
var assemblyPaths = _fileSystem.EnumerateBinaries(hostBin, SearchOption.TopDirectoryOnly);
141-
foreach (var path in assemblyPaths)
142-
{
143-
paths.Add(path);
144-
}
141+
paths.AddRange(assemblyPaths);
145142
}
146143
}
147144

148145
private IEnumerable<Lazy<IModule, IModuleMetadata>> GetLazyModules(CompositionContainer container)
149146
{
150-
IEnumerable<Lazy<IModule, IModuleMetadata>> lazyModules = null;
147+
IEnumerable<Lazy<IModule, IModuleMetadata>> lazyModules;
151148

152149
try
153150
{
@@ -166,8 +163,10 @@ private IEnumerable<Lazy<IModule, IModuleMetadata>> GetLazyModules(CompositionCo
166163
{
167164
_logger.DebugFormat("Module Loader exception: {0}", exception.Message);
168165
}
166+
169167
lazyModules = Enumerable.Empty<Lazy<IModule, IModuleMetadata>>();
170168
}
169+
171170
return lazyModules;
172171
}
173172
}

test/ScriptCs.Core.Tests/AssemblyResolverTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void ShouldOnlyReturnBinariesWhenFlagIsSet(
110110
AssemblyResolver resolver)
111111
{
112112
const string WorkingDirectory = @"C:\";
113-
113+
114114
var binFolder = Path.Combine(WorkingDirectory, "bin");
115115

116116
assemblyUtilityMock.Setup(a => a.IsManagedAssembly(It.IsAny<string>())).Returns(true);

0 commit comments

Comments
 (0)