Friday, 5 May 2017

c# - Using Directives, Namespace and Assembly Reference - all jumbled up with StyleCop!

I like to adhere to StyleCop's formatting rules to make code nice and clear, but I've recently had a problem with one of its warnings:



All using directives must be placed
inside of the namespace.



My problem is that I have using directives, an assembly reference (for mocking file deletion), and a namespace to juggle in one of my test classes:


using System;
using System.IO;
using Microsoft.Moles.Framework;
using Microsoft.VisualStudio.TestTools.UnitTesting;
[assembly: MoledType(typeof(System.IO.File))]
namespace MyNamespace
{
//Some Code
}

The above allows tests to be run fine - but StyleCop complains about the using directives not being inside the namespace.


Putting the usings inside the namespace gives the error that "MoledType" is not recognised.


Putting both the usings and the assembly reference inside the namespace gives the error



'assembly' is not a valid attribute
location for this declaration. Valid
attribute locations for this
declaration are 'type'. All attributes
in this block will be ignored.



It seems I've tried every layout I can but to no avail - either the solution won't build, the mocking won't work or StyleCop complains!


Does anyone know a way to set these out so that everything's happy? Or am I going to have to ignore the StyleCop warning in this case?

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...