Using Directives, Namespace and Assembly Reference - all jumbled up with StyleCop!
Posted
by Jack
on Stack Overflow
See other posts from Stack Overflow
or by Jack
Published on 2010-06-18T13:25:31Z
Indexed on
2010/06/18
13:33 UTC
Read the original article
Hit count: 459
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?
© Stack Overflow or respective owner