SetProperty in CSLA 3.6.0.0

SetProperty in CSLA 3.6.0.0

Old forum URL: forums.lhotka.net/forums/t/6597.aspx


vivitron posted on Wednesday, March 11, 2009

Greetings,

I'm working on an implementation of CSLA and wanted to use private backing fields instead of managed backing fields.

I also want the object to throw an exception if the current user does not have access to read the value or set the value... This is not the default implementation.

So, two options:
 (depreciated) CanReadValue(true);

or the new method:
return GetProperty<int>(_ProductIDPropertyInfo, _ProductID, _ProductIDPropertyInfo.DefaultValue, Csla.Security.NoAccessBehavior.ThrowException);

This works fine until I get to the SetProperty method which forces me to pass the string name of the Property as opposed to being able to pass the PropertyInfo object itself (like GetProperty does).

So I end up with this:

SetProperty<int>(_ProductIDPropertyInfo.Name, ref _ProductID, value, Csla.Security.NoAccessBehavior.ThrowException);

Any ideas why you can't do?
SetProperty<int>(_ProductIDPropertyInfo, ref _ProductID, value, Csla.Security.NoAccessBehavior.ThrowException);

Thanks for the help,
Dustin

RockfordLhotka replied on Wednesday, March 11, 2009

SetProperty() does throw an exception if the user isn't authorized, and so you should be able to use the default behavior there.

vivitron replied on Wednesday, March 11, 2009

Ah. My misunderstanding... That makes sense. So GetProperty does not always throw an exception, but SetProperty will.

Thanks for the help.

RockfordLhotka replied on Wednesday, March 11, 2009

Yes. GetProperty() doesn't throw, because that messes up most UI data binding technologies. SetProperty() does throw, because it doesn't conflict with data binding.

Copyright (c) Marimer LLC