c# - Nested classes don't have a namespace -
I am writing a custom FxCop-rule, which is that it checks exception class derived from the exception namespaces. It checks completely thorough work but, in my testcase, I came across some strange
namespace MyNamespace.IO {[TestClass] public class ExceptionsShouldOnlyInheritFromCorrectNamespacesTests {[TestMethod] Public Zero TestExceptionInheritanceNamespace () {RuleAssert.AssertProblemsAreEqualToExpectedProblems & Lt; ExceptionsShouldOnlyInheritFromCorrectNamespaces, ExceptionInhertTestClass & gt; (); }} Namespace some {[CaRuleTestClass] public class ExceptionInhertTestClass {public class MyFirstException: SystemException {} public class MySecondException: FileNotFoundException {} [ExpectedProblem] public class MyWrongException: AbandonedMutexException {}}}}
The code above shows the setup as you can see that I have a nested-namespace (this is only for testing). In this there is a main class ExceptionInhertTestClass
which holds three testclasses that are run by custom FxCop-rule.
This custom rule examines the namespace of the class and during this debate,
while debugging the rule, I saw that MySecondException
is an unexpected on -class There was a problem. No namespace was found for this class, of course. The picture shows:
why does not the class 'Nameshot is a value for the property, while it was clearly supposed to be?
Actually, it is logical to have namespace in them or not. Accordingly, the nested type metadata should actually contain an empty namespace (see page 11 on page 23). That is no way said, FxCop API is essentially metadata suit does not need to Benkajh a way that the device, however, since Microsoft FxCop rule does not provide an SDK for building, knowing that Its purpose can be here.
In other words, now you know that the namespace for nested type is not highlighted in this way, if you need it then you should ascend your declaration hierarchy to find the appropriate namespace. :)
Comments
Post a Comment