Archive
C# Using Alias Directive, Namespace Alias Qualifier and a sad story
Following up on my last post:
I’m copying from a mental note I added to:
http://stackoverflow.com/questions/4936941/using-a-using-alias-class-with-generic-types/11334359:
As shown at:
http://msdn.microsoft.com/en-us/library/sf0df423.aspx
and
http://msdn.microsoft.com/en-us/library/c3ay4x3d%28VS.80%29.aspx
you can do:
using gen = System.Collections.Generic;
using GenList = System.Collections.Generic.List<int>;
and then use
gen::List<int> x = new gen::List<int>;
or
GenList x = new GenList();
However:
you have to replicate those using definitions at every file where you use them, so if you make some changes to them in the future and forget to update at every file, things will break badly.
I hope C# in the future will treat aliases like the do with extension methods and let you define many of them in a file that you use elsewhere, then maintain them at one place and hide the internal unnecessary type mapping details from the type consumers.
BTW, another issue that makes me very sad to see reoccuring. Somebody (probably a moderator) replied at that StackOverflow page above that this was an old (some year and a half ago) discussion. My reply there (I’m glad that made him remove that remark, hope I proved the point):
I do know this is old discussion, but I just had the same issue and search engine took me here – why should I care if this is old discussion? Are we doing the news?
I get even worse behaviour in Microsoft Forums (or was it Microsoft Answers?) Silverlight Forums – moderators just delete any new posts at older discussion threads (they hadn’t even bothered to lock those discussions first). The just send you a lousy e-mail about the delection of your reply without sending you the deleted content (so the time you spent posting a sometimes detailed mental note as a reply there is totally wasted if you didn’t record that reply / mental note elsewhere). You can’t even reply to their e-mail with a counter argument.
They don’t really get it that people come across these matters again and again and they get to discussions that have partial information cause nobody bothered to add some mental notes after they found the answer to the issue.
The Silverlight Forums admin reply says:
The thread to which you have attempted to reply is a very old thread, and there is no value in reviving it. As a consequence, the above post has not been approved. Replying to very old threads (aka Necro-Posting) is discouraged on the forums as it moves those old threads ahead of the sites more recent threads. We ask all members who are offerring answers to please stick to the site’s more recent threads.
If only I could reply back (you can’t):
This is nonsense, search engines don’t care of the order you show them. People go there from search engine results and find poor, non-updated replies. Think for example some issue discussed and workarrounds posted. A visitor thinks it still occurs since nobody cared to note that some newer version of Silverlight fixed it / implemented it! Or imagine that there is now a better answer to a recurring old question (that search engines keep guiding people too) due to newer developments. Just fix your forum system to not bring very old-started threads to top unless admins decide to sticks them to top. Don’t waste our time please.
Those guys haven’t even bothered to update their e-mail templates and still have references to dead URLs like:
Your post was submitted as a reply to the following thread: http://forums-legacy.silverlight.net/forums/thread/410384.aspx
Since I couldn’t reply to the post delection e-mail (reply gets rejected), I opened up the issue at their forums, so please raise your voice there too if you agree with the above concerns:
http://forums.silverlight.net/p/258209/644711.aspx/1?p=True&t=634770152705948043
(wonder why that forum post doesn’t show up there currently – some people don’t like to hear the truth when it doesn’t suit them?)
Windows 7 Command Line Help mistake for IF command
If you type
help IF
at the Windows 7 command-line (can launch this by searching at Windows Start menu search box for “Command” or by typing cmd there and pressing ENTER), you get in one of the help pages printed out for the batch files’ IF command:
%ERRORLEVEL% will expand into a string representation of
the current value of ERRORLEVEL, provided that there is not already
an environment variable with the name ERRORLEVEL, in which case you
will get its value instead. After running a program, the following
illustrates ERRORLEVEL use:goto answer%ERRORLEVEL%
:answer0
echo Program had return code 0
:answer1
echo Program had return code 1
If a program you launched from the batch file returns error code 0 (meaning usually no error), then you jump to label (using “goto” command) answer%ERRORLEVEL% that is answer0 (labels are prefixed with : in DOS/Windows batch files) and it prints out (using echo command) on the console “Program had return code 0”.
Fine till here, but then it will proceed to next commands (the block labeled :answer1) and also print out “Program had return code 1”. Obviously the correct example should be:
goto answer%ERRORLEVEL%
:answer0
echo Program had return code 0
goto finish
:answer1
echo Program had return code 1
:finish
Could also have a goto finish after the last echo, but its needless since we don’t have :answer2 etc. labels after that and proceeds to finish by itself anyway.
Thinking of this example again, it’s a pretty silly one since one could do instead:
echo Program had return code %ERRORLEVEL%
BTW, to output an empty line to the console you can use echo:
And speaking of batch file tips, you can use :: for comment lines instead of REM command.