Hi gents,
Could someone point me in the general direction of the correct implementation of the ProspectHasChanged method in BusinessBase for CSLA4.
Having previously used CSLA 2.1, I'm trying to get to grips with the version 4 and having imported a couple of my 2.1 business classes from the old version, I've come across this breaking change.
This is a typical code snippet of my 2.1 business class:
Public Property TEAMNO() As String
Get
CanReadProperty(True)
Return mTEAMNO
End Get
Set(ByVal Value As String)
CanWriteProperty(True)
If mTEAMNO <> Value Then
mTEAMNO = Value
PropertyHasChanged()
End If
End Set
End Property
I haven't found a related thread so far, but will keep searching.
Thanks,
Graham
Hi,
The preferred property type is Managed property:
public static readonly PropertyInfo<int> Num1Property = RegisterProperty<int>(c => c.Num1); public int Num1 { get { return GetProperty(Num1Property); } set { SetProperty(Num1Property, value); } }
but you can still use private backing fields like this:
public static readonly PropertyInfo<int> Num2Property = RegisterProperty<int>(c => c.Num2,
RelationshipTypes.PrivateField); // [NotUndoable, NonSerialized] private int _name = Num2Property.DefaultValue; public int Num2 { get { return GetProperty(Num2Property, _name); } set { SetProperty(Num2Property, ref _name, value); } }
SetProperty will check CanWriteProperty and call PropertyHasChanged if the field value is changed.
You must also register properties in order to add BusinessRules or AuthorizationRules.
Confused now...
Are you saying I no longer have to implicity call the PropertyHasChanged method in my business class?
Your code snippets are from a business class or from the base class?
Compounding the confusion is probably my VB mindset.... but I can't determine context based on those examples... sorry.
Is there somewhere in the "Using CSL4:" books that discussed the actual implementation into a bix class?
Thanks,
Graham
Ok, a little less confusing now.
I managed to load the ProjectTracker.Library sample code - albeit in C# - and I see how the implementation has changed significantly. Yikes...
I should be able to garner what I need from that code... until I get stuck again
Thanks,
Graham
Hi,
You can still call PropertyHasChanged and OnPropertyChanged manually but you will need so supply an IPropertyInfo to identify the property.
But when you use the preferred property style you do not have to worry (or even thin) about this.
The old style PropertyHasChanged without parameters was VERY costly/slow due to the use of call stack and reflection.
Copyright (c) Marimer LLC