mercredi 1 avril 2015

Is there a more efficient way to define similar public properties


Vote count:

0




I've got a class with almost 20 public properties. These properties have in common that they are all strings and they are filled with data from different tables of a database.


Additionally the set is pretty normal while the get is special as I need to call a specific method. This is done for each property at the moment (see below).


My question here is: Is there another more efficient way of doing this, thus a way where I don't have to define each public property by hand in this way?



class myclass
{
private string _Firstname;
private string _Lastname;
.....
public string Firstname
{
get {
return ModifyStringMethod(this._Firstname);
}

set {
this._Firstname = value;
}
}
}


Like mentioned above every public property looks the same. The get calls ModifyStringMethod with the private member given as parameter while the set just sets the private member.



asked 54 secs ago

Thomas

160






Is there a more efficient way to define similar public properties

Aucun commentaire:

Enregistrer un commentaire