What is the best way to make a class property “Write Once, Read Many” such that you can only set the property once?
I know that I could pass all the properties in the constructor and make them ReadOnly, but in cases with a lot of properties I don’t want a constructor that has 20+ arguments.
Also, I realize I can “roll my own” setters, but having to do that for every property seems like a bunch of redundant coding.
Is there a clean way to do this in VB 2008 .NET 3.5?
A Write Once Property is never “clean”.
I’d recommend to create a builder/factory class to avoid the 20 param CTor.
(Yes, I know it is quite some typing)
Similar discussion here:
Should I use set once variables?
[edit] Furthermore, even if you insist I don’t see another option than rolling your own setters, which is a lot of typing, too.