I want to create a business entity. I want to store additional information with each property
e.g.
Public Class BE
{
private string _fundCity;
public string FUND_CITY
{
get { return _fundCity; }
set { _fundCity = value; }
}
}
For FUND_CITY i want to store “StartOffSet” and “EndOffSet” values in BE.
Can some one help.
If you want to have properties that are directly related to
FUND_CITYthen normally you would make it an object in its own right and add the properties to the new object, and you can still store it in your objectBEas you are now.If you want
FUND_CITYto remain as a string, then you must addStartOffsetandEndOffsetas properties on theBEclass, just as you have with FUND_CITY. I would give you an example but you haven’t specified what types those two properties are.EDIT:
It sounds like what you need is a wrapper class with a shot of generics. If you want to track
StartOffsetandEndOffsetfor every property onBE, then first create a generic class that will be used for each property in BE:PropertyValueis used to hold (or wrap) the actual value of the property. Your classBEthen changes to look like this:you can then use it like this:
If you want to go still further and keep a list of these, then you can use the inbuilt generic List<T> type, but then you have a small issue: the List<T> wants all its contents to be of the same type. You can get round this either by using a base class, or by just casting everything in the List<T> to type
object. Here is an example of using the base class, it has a small change from the code above: