Hi
I would like to use an objects property as the key for a dictionary. Can this be done?
The ultimate goal for this is to use this so can see if the property is locked or not, in various states that an object can be in. These locked value is not persisted, just exist in the business rules for the model.
Ideal code to see if field is locked would look like this;
bool ageLocked = myObject.IsFieldLocked( x => x.Age);
bool nameLocked = myObject.IsFieldLocked(x => x.Name);
IsFieldLocked being an extension method for the type of myObject.
I would like the dictionary to live in myObject and be replaceable with different dictionary variations based on the state of the object, for example, has placed an order or awaiting order would have different dictionary definitions.
Hopefully I would be able to use a a factory to create the different dictionary variations;
Factory.CreateAwaitingOrderLockedFields()
Factory.CreateOrderPlacedLockedFields()
Defining the dictionary looking something like this
new Dictionary< ***MissingMagic***, bool>()
{
{ x => x.Age , true},
{ x => x.Name, false}
}
Aim is to avoid the key being a string, strongly typed key by far more desirable.