Permalink
Browse files

Modified IsInNamespace to check for null Namespace property on type p…

…arameter, to prevent NullReferenceException if an assembly contains a type outside any namespace. Added test to AssemblyScannerTester to test for this scenario.
  • Loading branch information...
Ryan Rounkles
Ryan Rounkles committed Dec 29, 2011
1 parent a1acf25 commit 5c472496cd632ae63e1241680a1e92432c9c2f9e
@@ -113,6 +113,13 @@ public void is_in_namespace()
GetType().IsInNamespace("StructureMap.Testing.Graph.Something").ShouldBeFalse();
}
+ [Test]
+ public void class_outside_namespace_doesnt_match_any_namespace_check()
+ {
+ typeof(class_outside_namespace).IsInNamespace("blah").ShouldBeFalse();
+ typeof(class_outside_namespace).IsInNamespace("StructureMap").ShouldBeFalse();
+ }
+
[Test]
public void Only_scan_for_registries_ignores_attributes()
{
@@ -424,4 +431,9 @@ public void can_find_objects_later_by_name()
.ShouldBeOfType<SiteController>();
}
}
+}
+
+public class class_outside_namespace
+{
+
}
@@ -74,7 +74,7 @@ public static bool Closes(this Type type, Type openType)
public static bool IsInNamespace(this Type type, string nameSpace)
{
- return type.Namespace.StartsWith(nameSpace);
+ return type.Namespace != null && type.Namespace.StartsWith(nameSpace);
}
public static ReferencedInstance GetReferenceTo(this Type type)

0 comments on commit 5c47249

Please sign in to comment.