I am a big fan of StyleCop, it makes my life easier. A bunch of other people have thought of good rules, and I gladly follow them by enabling StyleCop. Recently I have been messing with Coded Ui extensibility, and came across this article:
http://blogs.msdn.com/b/gautamg/archive/2010/01/05/2-hello-world-extension-for-coded-ui-test.aspx
The sample code below makes StyleCop unhappy because the using
statements are outside of the namespace. However, I can move only the two System*
packages in - the third is needed to define an assembly attribute, and I cannot throw assembly:
inside of a namespace.
Is there a clean way to re-organize this code?
using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UITest.Common;
using Microsoft.VisualStudio.TestTools.UITest.Extension;
// Attribute to denote that this assembly has UITest extensions.
[assembly: UITestExtensionPackageAttribute("HelloWorldPackage",
typeof(UITestHelloWorldPackage.HelloWorldPackage))]
namespace UITestHelloWorldPackage
{
internal class HelloWorldPackage : UITestExtensionPackage
{
public override object GetService(Type serviceType)
{
Trace.WriteLine("Hello, World");
return null;
}
....
IMHO, the rule to put usings inside the namespace is useless and makes the code hard to read.
Can't you move your [assembly: UITestExtensionPackageAttribute()]
attribute to your Properties\AssemblyInfo.cs file? I'm guessing the article you referenced had the [assembly:]
attribute there just to keep the example in a single block of code.
I agree with Daniel - having using
statements inside namespaces makes your code harder to read.
I'd recommend moving the attribute to your AssemblyInfo.cs file and keep your usings at the top of your class file. That seems pretty standard.
Hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With