Hello,
I'm new to C# (started last week) so be cool with me ;). I'd like to know if I can somehow write a custom property, let me explain:
I have some partial classes that I complete by adding properties, but the pattern of all the getters and setters are the same so I'd like to factorize this:
public partial class Travel
{
public String TravelName
{
get
{
return LocaleHelper.GetRessource(Ressource1);
}
set
{
if (this.Ressource1 == null)
Ressource1 = new Ressource() { DefaultValue = value };
else
Ressource1.DefaultValue = value;
}
}
public String TravelDescription
{
get
{
return LocaleHelper.GetRessource(Ressource2);
}
set
{
if (this.Ressource2 == null)
Ressource2 = new Ressource() { DefaultValue = value };
else
Ressource2.DefaultValue = value;
}
}
}
As you can see, the only thing that change is Ressource1/Ressource2. My goal is be able to write something like:
public partial class Travel
{
public LocalizedString TravelName(Ressource1);
public LocalizedString TravelDescription(Ressource2);
}
Anybody have an idea to make this, or another idea to make my code cleaner? Thank you,
Guillaume