The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,854 other subscribers

Archive for the ‘C# 2.0’ Category

a BNF grammer for C# v2 and ANTLR grammers for C# v2 and C# v4 (via: c# 4.0 – C# grammar in BNF or EBNF Parser generator for F# – Stack Overflow)

Posted by jpluimers on 2012/04/11

a BNF grammer for C# v2 has moved from www.devincook.com/GOLDParser/grammars/index.htm to  goldparser.org/grammars.

It is mostly complete, and a good learning experience to both BNF and the C# syntax.

ANTLR grammers are available for C# 2, and a partially for C# 4.

–jeroen

via: c# 4.0 – C# grammar in BNF or EBNF Parser generator for F# – Stack Overflow.

Posted in .NET, C#, C# 2.0, Development, Software Development | Leave a Comment »

Getting the public static readonly strings and public const strings (and their values) from a class

Posted by jpluimers on 2012/04/03

Quite a few projects have one or more classes with with a bunch of public const string or public static readonly string values. Use const when things are really constant (like registry configuration keys), use static readonly when – upon change – I do not want to recompile dependent assemblies. Many people recommend static readonly over const.

Having members in stead of string literals scattered all over the place allows you to do compile timing checking, which I’m a big fan of as in the age of things getting more and more dynamic, you need to have as many sanity checks as possible.

One of the checks is to verify these const members and their values. Sometimes you need the list of members, sometimes the list of values, and sometimes each member value should be the same as the member name.

The listing below shows the code I came up with.

It works with code like this, and those can have more code and other fields (non string, non public) in them as well:

namespace bo.Literals
{
    public class FooBarPublicStringConstants
    {
         public const string Foo = "Foo";
         public const string Bar = "Bar";
    }
    public class FooBarPublicStaticReadOnlyStringFields
    {
         public static readonly string Foo = "Foo";
         public static readonly string Bar = "Bar";
    }
}

I started out with this code, but that is limited to classes only having public const fields. Not flexible enough. Read the rest of this entry »

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development | Leave a Comment »

KB2251481 update issues (via: MS11-049: Description of the security update for Visual Studio 2005 SP1: June 14, 2011)

Posted by jpluimers on 2012/03/29

August 2011, Microsoft re-issued KB2251481. They should not have done that, because if you have the original KB2251481 installed (also known as KB2251481.T369_32ToU865_32) you need to go through the hoopla below to uninstall it.

In stead, they should have released a new version that automatically uninstalls a previously installed one, then installs itself.

It is not the first patch that Microsoft did wrong, but this one is the “Microsoft Visual Studio 2005 Service Pack 1 XML Editor Security Update”. Every now and then I come across it when doing work on some archived virtual machines that contain Visual Studio 2005 (which I used a lot in the past, and occasionally still use for doing some maintenance work for clients that long ago ditched stuff they thought they’d never need to use again).

The really stupid thing is the error message you get when it cannot get installed: John Doe user will never find out why it failed, let alone figure out how to get it install properly.

This is the message you will see:

[Automatic Updates]
Some updates could not be installed
The following updates were note installed:
Security Update for Microsoft Visual Studio 2005 Service Pack 1 XML Editor (KB2251481)
[Close]

The message doesn’t even include that it is trying to install the August 2011 version (hinting that there might be an earlier version you need to uninstall). Read the rest of this entry »

Posted in .NET, C#, C# 2.0, Development, Software Development, Visual Studio 2005, Visual Studio and tools | Leave a Comment »

naming – What’s the use/meaning of the @ character in variable names in C#? – Stack Overflow

Posted by jpluimers on 2012/03/28

Duh, I always thought @ could only be used for strings.

Not so: just like with the & in Delphi is used to escape keywords, the additional use of @ in C# is to escape identifiers:

The prefix “@” enables the use of keywords as identifiers, which is useful when interfacing with other programming languages. The character @ is not actually part of the identifier, so the identifier might be seen in other languages as a normal identifier, without the prefix. An identifier with an @ prefix is called a verbatim identifier.

–jeroen

via: naming – What’s the use/meaning of the @ character in variable names in C#? – Stack Overflow.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Delphi, Development, Software Development | Leave a Comment »

reflection – C# – Resolving a parameter name at runtime – Stack Overflow

Posted by jpluimers on 2012/03/27

So I won’t forget: a GetName method returning the name of a parameter, local or field.

Tags: C#, reflection, IL parsing, argument name, anonymous type, generic type cachegeneric type caching.

–jeroen

via: reflection – C# – Resolving a parameter name at runtime – Stack Overflow.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development | 4 Comments »

WTF C# code of the month

Posted by jpluimers on 2012/03/14

When I come across code like this, I’m always astonished:

			catch(Exception ex)
			{
				string strMess = ex.Message;
			}

What was the person thinking when he wrote this? Did he get distracted and nobody else notice this before checking it into their version control system?

In the same module:

		private string ToString(object myVal)
		{
			try
			{
				if (myVal != System.DBNull.Value)
					return myVal.ToString().Trim();
			}
			catch{}

			return "";
		}

–jeroen

Posted in .NET, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Development, Software Development | Leave a Comment »

Eric Lippert’s comment and answer explaining nullable operator lifting (c# – Why does the == operator work for Nullable when == is not defined? – Stack Overflow)

Posted by jpluimers on 2012/03/07

It seems I’m not the ony one who watches what Eric Lippert writes closely.

Eric works at the C# team at Microsoft (since 1996, which is about the time Anders Hejlsberg joined Microsoft).

Unlike Anders, Eric is much more visible. I regularly read his blog, and watch his StackOverflow.com contributions (RSS feed) on a regular base.

Recently, he posted a awesome comment “Nullable is nothing but magic” on a the question “C# – Why does the == operator work for Nullable when == is not defined?“, together with a very concise answer explaining that in C# most operators are ‘lifted to nullable’.

Note his tiny – but important – mention that for == VB.net behaves different than C#.

Note that Eric is very productive, he usually contributes to StackOverflow.com multiple times a day, sometimes with material that (at least for me <g>) need a while before I really get the point.

Recommended reading :)

–jeroen

via: c# – Why does the == operator work for Nullable when == is not defined? – Stack Overflow.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development, VB.NET | Leave a Comment »

Anyone with a C#, Delphi or FreePascal implementation of the PRESENT Ultra-Lightweight Block Cipher encryption?

Posted by jpluimers on 2012/03/06

A short while ago a paper got published on PRESENT: An Ultra-Lightweight Block Cipher by Andrey Bogdanov et al becoming ISO standard 29192-2:2012.

Is there anyone that has a C#, Delphi or FreePascal implementation with unit tests?

–jeroen

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, Delphi, Development, Software Development | 13 Comments »

Free .NET Decompiler – JustDecompile from Telerik

Posted by jpluimers on 2012/02/17

Interesting:

JustDecompile is a new, free developer productivity tool for easy .NET assembly browsing and decompiling.

–jeroen

via: Free .NET Decompiler – JustDecompile.

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Development, Software Development, VB.NET | Leave a Comment »

What’s new in .NET Framework 4.5? [poster] (via Heikniemi Hardcoded)

Posted by jpluimers on 2012/02/14

What’s new in .NET Framework 4.5? [poster] (via Heikniemi Hardcoded)I love the “Async ja Await equal to C#” in the picture and the copy-paste re-use in this blog entry from msguy.

Jouni Heikniemi originally posted “What’s new in .NET Framework 4.5 [poster]” on 20111029, then updated the poster on 20111116.

His original poster is Finnish, and his English poster contains a small translation glitch “Async ja Await equal to C#” (“ja” is Finnish for “and”).

Both posters are PNG filess, so msguy Anil made it into a textual document, including the translation glitch.

I love that, as it shows we are all humans :)

–jeroen

via: Bruno Leonardo Michels – Google+.

Posted in .NET, .NET 4.5, C# 2.0, C# 5.0, Software Development | 4 Comments »