ReadOnly in Csla.Core.IPropertyInfo

ReadOnly in Csla.Core.IPropertyInfo

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


jlfernandezmiranda posted on Tuesday, April 27, 2010

I have been studying Csla.Core.IPropertyInfo interface and I could not to find an answer. I need to check If a property is ReadOnly.

For Each prop As IPropertyInfo In FieldManager.GetRegisteredProperties

........ How to check here if prop Is ReadOnly?

Next

Any Ideas? Thanks

ajj3085 replied on Tuesday, April 27, 2010

You should be able to call CanWriteProperty method using the information from the property info instance.

jlfernandezmiranda replied on Tuesday, April 27, 2010

 I can´t call CanWriteProperty Andy, my code is the follow: 

Public Module HelperModule

Public Sub AutorizatePropsPerType(ByVal NamespaceRoot As String, ByVal Ar As AuthorizationRules, ByVal FM As FieldDataManager)

 F

 

 

or Each prop As IPropertyInfo In FM.GetRegisteredProperties

 T

ry

 '''''''  If prop is ReadOnly i want to bypass this line

 Ar.AllowWrite(prop.Name, NamespaceRoot + prop.Name + ".Write")

'''''' but this line is checked Always

Ar.AllowRead(prop.Name, NamespaceRoot + prop.Name + 

 

".Read")

 Catch ex As Exception 

 Throw New ApplicationException("Failed Autorization Rules at method AuthorizatedPropsPerType, location: HelperModule." + ex.Message + ex.StackTrace)

 E

nd Try

 

Next

 E

 

nd Sub

 

 

 

 End Module

So in a BussinessBase Class I do

Public Class Customer : Inherits BusinessBase(Of Customer)

'Here I declare Props

...............

 Protected Overrides Sub AddAuthorizationRules()

 AutorizatePropsPerType("MyApp.Customers." , Me.AuthorizationRules, Me.FieldManager) 

End Sub

End Class

 Thanks

 

 

 

jlfernandezmiranda replied on Tuesday, April 27, 2010

 I can´t call CanWriteProperty Andy, my code is the follow: 

Public Module HelperModule

Public Sub AutorizatePropsPerType(ByVal NamespaceRoot As String, ByVal Ar As AuthorizationRules, ByVal FM As FieldDataManager)

 

 

For Each prop As IPropertyInfo In FM.GetRegisteredProperties

 

Try

 

'''''''  If prop is ReadOnly i want to bypass this line

 Ar.AllowWrite(prop.Name, NamespaceRoot + prop.Name +".Write")

'''''' but this line is checked Always

Ar.AllowRead(prop.Name, NamespaceRoot + prop.Name +

 

".Read")

  Catch ex As Exception

 

Throw New ApplicationException("Failed Autorization Rules at method AuthorizatedPropsPerType, location: HelperModule." + ex.Message + ex.StackTrace)

 

End Try

 

Next

 

 

End Sub

 

 

 

 

End Module

So in a BussinessBase Class I do

Public Class Customer : Inherits BusinessBase(Of Customer)

'Here I declare Props

...............

 

Protected

 

 

Overrides Sub AddAuthorizationRules()

 AutorizatePropsPerType("MyApp.Customers." , Me.AuthorizationRules, Me.FieldManager) 

End Sub

End Class

 Thanks

 

 

 

RockfordLhotka replied on Tuesday, April 27, 2010

The simplest way to determine if a .NET property is read-only is to use the .NET PropertyDescriptor and TypeDescriptor subsystem in System.ComponentModel. This doesn't exist on Silverlight, but it is the simplest thing to do in .NET.

You can see examples of its use if you search the CSLA codebase for "TypeDescriptor" - I believe it is used in DataMapper, and in the Csla.Web functionality, and perhaps other places.

jlfernandezmiranda replied on Tuesday, April 27, 2010

Thanks Rocky, you fixed my issue. I will study to find an answer for Silverlight.

RockfordLhotka replied on Tuesday, April 27, 2010

In Silverlight you use standard System.Reflection types like PropertyInfo. It isn't as easy as PropertyDescriptor, but you can infer the read-only status with some care. I think I do this in the PropertyStatus control in SL if I remember correctly.

Copyright (c) Marimer LLC