Oh And Did You Know… (Another CodeDOM Rant)

For today’s CodeDOM rant, I’d like to talk about the readonly keyword (otherwise known as InitOnly).

As you all know, readonly, when placed on a field, means that the field is to be treated as a constant, but can be initialized in the constructor, instead of inline.

public class MyClass
private readonly int i;
private const int j = 0;
public MyClass()
i = 0;

This helps if you’re trying to do some hardcore initialization for the field that can’t be done inline.

The problem is that this doesn’t appear in Microsoft’s CodeDOM.
That’s right, you can’t generate readonly fields.



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s