Properties/ set+get methods

  • Thread starter Thread starter James Scott
  • Start date Start date
J

James Scott

hello,

is there a way to write set&get methods more compact?

I have a bout 50 properties that I have to acesss - and that's a lot of
redundant code.

Another way I can think of is putting the values in a Hashtable. Or are
there (big) disadvantages to that?


Thanks!
 
James,

The big disadvantage to the hashtable is that you will give up
type-safety (since it returns objects). The only way you could do something
like this is if all of the properties were of the same type, then you could
create a type-safe hashtable (or use a Generic dictionary in .NET 2.0) which
is indexed on some sort of pre-defined key.

However, if they are of different types, I really would recommend
against this, as it would make your class sloppy and difficult to use. If
anything, I would bite the bullet. It is a lot of work upfront, but down
the line, you will be glad you did it.

Also, if you are using VS.NET 2005, you can use expansions (there is one
for property) which will basically insert a property declaration and query
you for the various aspects of the property (the field name, the type, the
property name).

Hope this helps.
 
Back
Top