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
You should be able to call CanWriteProperty method using the information from the property info instance.
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
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 +
Catch ex As Exception
Throw New ApplicationException("Failed Autorization Rules at method AuthorizatedPropsPerType, location: HelperModule." + ex.Message + ex.StackTrace)
E
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
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)
''''''' 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 +
Catch ex As Exception
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
AutorizatePropsPerType("MyApp.Customers." , Me.AuthorizationRules, Me.FieldManager)
End Sub
End Class
Thanks
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.
Thanks Rocky, you fixed my issue. I will study to find an answer for Silverlight.
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