Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Minor improvements #883

Merged
merged 2 commits into from

2 participants

@synhershko

Mostly related to the use of Dictionaries

src/Nancy/ViewEngines/ResourceViewLocationProvider.cs
@@ -80,11 +80,11 @@ private IEnumerable<ViewLocationResult> GetViewLocations(Assembly assembly, IEnu
throw new InvalidOperationException(errorMessage);
}
- var commonNamespace = RootNamespaces.ContainsKey(assembly) ?
- RootNamespaces[assembly] :
- ExtractAssemblyRootNamespace(assembly);
+ string commonNamespace;
+ if (!RootNamespaces.TryGetValue(assembly, out commonNamespace))
+ commonNamespace = ExtractAssemblyRootNamespace(assembly);
@thecodejunkie Owner

single-line if-statements should be wrapped in curly-braces

Wow, you are picky :)

Btw, why isn't RootNamespaces a ConcurrentDictionary?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/Nancy/ViewEngines/ResourceViewLocationProvider.cs
@@ -155,7 +155,9 @@ private static string GetResourceFileName(string resourceName)
private static string GetResourceExtension(string resourceName)
{
- return Path.GetExtension(resourceName).Substring(1);
+ var extension = Path.GetExtension(resourceName);
+ if (extension != null) return extension.Substring(1);
@thecodejunkie Owner

Replace with return (extension != null) ? extension.Substring(1) : string.Empty;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@thecodejunkie

With ~100 contributors and a ton of code you cannot have 100 different code conventions running amok in the code base or you'll pretty soon end up with a royal mess. Broken Windows principle http://pragprog.com/the-pragmatic-programmer/extracts/software-entropy

It's not a ConcurrentDictionary because it was not designed to be altered at run-time. Reading from multiple threads is never an issue

@thecodejunkie thecodejunkie merged commit 6b2f1b1 into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 29, 2012
  1. @synhershko

    Minor improvements

    synhershko authored
  2. @synhershko
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 7 deletions.
  1. +10 −7 src/Nancy/ViewEngines/ResourceViewLocationProvider.cs
View
17 src/Nancy/ViewEngines/ResourceViewLocationProvider.cs
@@ -17,12 +17,12 @@ public class ResourceViewLocationProvider : IViewLocationProvider
/// <summary>
/// User-configured root namespaces for assemblies.
/// </summary>
- public static IDictionary<Assembly, string> RootNamespaces = new Dictionary<Assembly, string>();
+ public readonly static IDictionary<Assembly, string> RootNamespaces = new Dictionary<Assembly, string>();
/// <summary>
/// A list of assemblies to ignore when scanning for embedded views.
/// </summary>
- public static IList<Assembly> Ignore = new List<Assembly>();
+ public readonly static IList<Assembly> Ignore = new List<Assembly>();
/// <summary>
/// Initializes a new instance of the <see cref="ResourceViewLocationProvider"/> class.
@@ -80,11 +80,13 @@ private IEnumerable<ViewLocationResult> GetViewLocations(Assembly assembly, IEnu
throw new InvalidOperationException(errorMessage);
}
- var commonNamespace = RootNamespaces.ContainsKey(assembly) ?
- RootNamespaces[assembly] :
- ExtractAssemblyRootNamespace(assembly);
+ string commonNamespace;
+ if (!RootNamespaces.TryGetValue(assembly, out commonNamespace))
+ {
+ commonNamespace = ExtractAssemblyRootNamespace(assembly);
+ }
- if (string.IsNullOrEmpty(commonNamespace))
+ if (string.IsNullOrWhiteSpace(commonNamespace))
{
return Enumerable.Empty<ViewLocationResult>();
}
@@ -155,7 +157,8 @@ private static string GetResourceFileName(string resourceName)
private static string GetResourceExtension(string resourceName)
{
- return Path.GetExtension(resourceName).Substring(1);
+ var extension = Path.GetExtension(resourceName);
+ return extension != null ? extension.Substring(1) : string.Empty;
}
}
}
Something went wrong with that request. Please try again.