Although I think that the use of reflection to retrieve the property name is really cool, I don’t think this is necessarily a good idea. The reason I say that is because property names are used in many other places such as on the rule validation functionality for example and because of this, you now have to be really careful about keeping everything in sync. In other words, if the property name changes you also need to change the rest of the code.
So from my point of view, if you have to manually specify the property name by typing the actual property name in multiple places, you better come up with a way to minimize potential for error and code maintainability.
This is way I think that rather than typing the property name such as “SomePropertyName” wherever is required, I think you are much better off creating public static string that you can share all over. Below is an example of what I am talking about:
public static readonly string PROP_START_TIME = “StartTime”;
The reason why it’s public is because the client code that needs the name of the property can use this exposed constant value to do thing such as retrieve the broken rules for a certain property. The reason why is readonly and not a constant is to avoid versioning problems.
Now, if you ever need to change the property name then you only have to change it in one place but most importantly, you **DON’T** have to tell everyone that is using your dll to change the value.
If you where to change the PROP_START_TIME value to something like PROP_STARTO_THE_TIMO the client code will get compile errors making it very obvious that they need to adjust the code to comply with the new changes.
Also, I not sure if this will work since I never done it but I think you can change the above code to something like:
public static readonly string PROP_START_TIME = Guid.NewGuid().ToString();
This way you can spare yourself of the task of having to synchronize the string value with the property name.
Usage example:
CanReadProperty(PROP_START_TIME, true);
CanWriteProperty(PROP_START_TIME, true);
PropertyHasChanged(PROP_START_TIME);
ValidationRules.AddRule(MyDelegate, PROP_START_TIME);