I would like to use the property of objects as a key for a dictionary. It can be done?
The ultimate goal for this is to use this so that you can see whether the property is locked or not, in different states in which the object may be. These locked values ββare not saved, they simply exist in the business rules for the model.
The ideal code to see if a field is locked would look like this:
bool ageLocked = myObject.IsFieldLocked( x => x.Age); bool nameLocked = myObject.IsFieldLocked(x => x.Name);
IsFieldLocked is an extension method for type myObject.
I would like the dictionary to work in myObject and be replaced by various variations of the dictionary based on the state of the object, for example, place an order or expect an order, have different dictionary definitions.
Hope I can use factory to create different variations of the dictionary;
Factory.CreateAwaitingOrderLockedFields() Factory.CreateOrderPlacedLockedFields()
Defining a dictionary like this
new Dictionary< ***MissingMagic***, bool>() { { x => x.Age , true}, { x => x.Name, false} }
The goal is to avoid the key being a string, a strongly typed key is much more desirable.
c00ke source share