I have a number of class objects, each of which needs a URL field which is always formatted in the same way via parameter TypeId, another property of the class.
What is the best way to abstract this as a dynamic property so the URL field is generated based on the TypeId and ItemId properties from the class.
I can think of many ways to do this but wondered what the recommended practice was.
Example below:
public class MyObject
{
public int Id { get; set; }
public string URL
{
get
{
if (TypeId == 3)
{
return "/do/this/" + ItemId;
}
if (TypeId == 5)
{
return "/do/that/" + ItemId;
}
return "#";
}
}
public int ItemId { get; set; }
public int TypeId { get; set; }
}