Possible framework enhancement: Function CanGetProperty(prop As IPropertyInfo) As Boolean etc.

Possible framework enhancement: Function CanGetProperty(prop As IPropertyInfo) As Boolean etc.

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


stefan posted on Wednesday, June 17, 2009

Hi @ all!

I often run into a situation where I have to check for authorization against multiple properties, e. g.:

Public ReadOnly Property UnitOfQuantity as String
  Get
    If CanReadProperty(ItemQuantityProperty.Name) OrElse _  
        CanReadProperty(UnitOfQuantityProperty.Name) Then
      Return ReadProperty(Of String)(UnitOfQuantityProperty)
    Else
      Return String.Empty
    End If 
  End Get
End Property


I then cannot make use of all the features provided by the framework's GetProperty implementation.

The problem here is, that this code does not take into account the BypassPropertyChecks-feature.
More important yet, in the past many of us have overridden the CanReadProperty/CanWriteProperty
implementations, which did not know about BypassPropertyChecks. On the other hand, following the
standard pattern with ... return GetProperty(Of String)(UnitOfQuantityProperty), both features are
considered (ByPassPropertyChecks AND CanReadProperty).

I really would like to see functions like
CanGetProperty(propInfo As IPropertyInfo) As Boolean
and
CanSetProperty(propInfo As IPropertyInfo) As Boolean
that enable us to take full advantage of the BypassPropertyChecks feature.
Then we could always call the public properties instead of having to implement special friend/internal
methods that bypass authorization!

Looks like an easy change to me. Only extract the part that already does the checks into these new
public functions...

What do you think, Rocky?

Stefan

RockfordLhotka replied on Wednesday, June 17, 2009

I'll add this to the wish list. Though another solution is to give you a protected property that tells you whether bypass property checks is turned on/off and allow you to use it as you choose.

Copyright (c) Marimer LLC