Answered by:
Compiler warning for unused alias?

Question
-
Hi,
I regularly use aliases when using deeply nested enumerations such as:
using e7 = MY_NAMESPACE.CAllEnumerations.ENUMERATION7;and then instead of having to type:
int ThisValue = MY_NAMESPACE.CAllEnumerations.ENUMERATION7.FIELD3;I can type:
int ThisValue = e7.FIELD3; // Sweet...My question is whether there is any way for the compiler to warn me of unused aliases? For example, if I add an alias for ENUMERATION6 and ENUMERATION7, but then delete references to ENUMERATION6, can the compiler find the line:
using e6 = MY_NAMESPACE.CAllEnumerations.ENUMERATION6;and warn me about it? Using VS2005.
Thanks,
AlainMonday, September 17, 2012 3:11 PM
Answers
-
Well, I have only VS2010 at hand. Here we have Organize Usings > Remove and Sort in the code editor, which does that for us..
- Proposed as answer by Jason Dot WangModerator Wednesday, September 19, 2012 7:56 AM
- Marked as answer by Jason Dot WangModerator Tuesday, September 25, 2012 8:12 AM
Monday, September 17, 2012 4:03 PM -
Well, I have only VS2010 at hand. Here we have Organize Usings > Remove and Sort in the code editor, which does that for us..
Remove Unused Usings is new in 2010 (http://msdn.microsoft.com/en-us/library/bb514114(v=vs.100).aspx).Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Proposed as answer by Jason Dot WangModerator Wednesday, September 19, 2012 7:56 AM
- Marked as answer by Jason Dot WangModerator Tuesday, September 25, 2012 8:12 AM
Monday, September 17, 2012 4:07 PMModerator
All replies
-
Why dont see show us whole code?
It seems that ENUMERATION6 AND 7 are integer fields (or propperties), but I dont know what you wanna ask it!?
If there field (or property) exists, compiler will say notihng, else it will.
Mitja
Monday, September 17, 2012 3:38 PM -
If you mean can you delete the using statements, such as in.....
using MY_NAMESPACE.CAllEnumerations.ENUMERATION7.FIELD3; using e7 = MY_NAMESPACE.CAllEnumerations.ENUMERATION7;
....and deleting the first line, then compile it and see what happens. Because the second line used the fully namespace name, then the compiler should be able to resolve the type in the referenced assembly. Also, the "using e7" line above has a scope limited to the file in which it appears. This is true, as you may not have noticed, for all using statements that appear at the top of code files.
Rudy =8^D
Mark the best replies as answers. "Fooling computers since 1971."
Monday, September 17, 2012 3:46 PMModerator -
The compiler will not warn you about unused, existing aliases. There are many third party tools that will handle this, however. For example, Resharper includes an option that will remove all unused aliases in a file. I believe a similar option is available in CodeRush and other similar code-assist products.
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".Monday, September 17, 2012 3:50 PMModerator -
Well, I have only VS2010 at hand. Here we have Organize Usings > Remove and Sort in the code editor, which does that for us..
- Proposed as answer by Jason Dot WangModerator Wednesday, September 19, 2012 7:56 AM
- Marked as answer by Jason Dot WangModerator Tuesday, September 25, 2012 8:12 AM
Monday, September 17, 2012 4:03 PM -
Well, I have only VS2010 at hand. Here we have Organize Usings > Remove and Sort in the code editor, which does that for us..
Remove Unused Usings is new in 2010 (http://msdn.microsoft.com/en-us/library/bb514114(v=vs.100).aspx).Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".- Proposed as answer by Jason Dot WangModerator Wednesday, September 19, 2012 7:56 AM
- Marked as answer by Jason Dot WangModerator Tuesday, September 25, 2012 8:12 AM
Monday, September 17, 2012 4:07 PMModerator -
Thanks for the response, Reed. I'll have a look at Resharper.
Regards,
Alain<Reed Copsey>; <Jr [MVP]> wrote in message news:887e244a-416e-4165-9867-717c7a0d43a8@communitybridge.codeplex.com...
Well, I have only VS2010 at hand. Here we have Organize Usings > Remove and Sort in the code editor, which does that for us..
Remove Unused Usings is new in 2010 (http://msdn.microsoft.com/en-us/library/bb514114(v=vs.100).aspx).
Reed Copsey, Jr. - http://reedcopsey.com <http://reedcopsey.com>
If a post answers your question, please click "*Mark As Answer*" on that post and "*Mark as Helpful*".Monday, September 17, 2012 5:18 PM -
It already existed in Visual Studio 2008.
Looks like that's when it was added:
http://blogs.msdn.com/b/djpark/archive/2008/08/16/organize-usings-across-your-entire-solution.aspx
"One of the features I worked on for the Visual Studio 2008 release was the new "Organize Usings" feature."
Wednesday, September 19, 2012 10:05 AM