Hi Gang
Just a small question recently migrated to 3.5 and noticed all the changes with the way properties work etc, and my question relates to calculations. VB.Net
Old 3.x you would do something like this
private mproperty1 as int16
private mproperty2 as int16
property Property1 as int16
etc and then if you were calculating you would just go
Dim manswer1 as int16
manswer1 = mproperty1 * mproperty2
how do you do that type of thing now ?
Thanks in advance
Ellie
SetProperty<int>(manswer1, GetProperty<int>(mproperty1) * GetProperty<int>(mproperty2));
That would bypass the authorization checks, setting dirty etc and will set the private member values directly. Hope this helps.
I think if you want to bypass the authorization checks you may want to use ReadProperty and LoadProperty. You would not, however, get any triggers for PropertyHasChanged, marking the object as dirty or checking validation rules for manswer1, so certainly keep that in mind.
Using LoadProperty on a managed property really has a similar effect to setting a private field in pre managed property code.
Thanks guys,
isn't the long way round i mean if i have a calcualtion which is within the BO and uses five or six properties the formulas are going to become unreadable.
Thanks
Ellie
It's a trade-off - I agree, you do lose a little readability.
If you used private backing fields (I don't, but you can) then you'd be able I imagine to use them directly in your formula. Additionally, I believe Rocky has said they are more performant overall.
For more complex calculations (or esp if I'm reusing the result), sometimes I'll do ReadProperty calls into local variables so that my calculations are easier to read.
i was originally using private or protected variables behind the properties as in (edited)
Dim mInvoiceNo As int16
Public Property InvoiceNo as Int16
Get
Return mInvoiceNo
Set
mInvoiceNo = value
Therefore the calculations used the mInvoiceNo variable not InvoiceNo the property.
Are the private backing fields the equivalent ? and how do you blend them with the new structure of PropertyInfo etc.
Thanks for the assistance
Ellie
If readability is your only reason for avoiding managed fields, keep in mind that the earlier example can be refactored as:
SetProperty<Int16>(manswer, MProperty1 * MProperty2)
assuming that you have properties called MProperty1 and MProperty2 that implement the GetProperty method to return the values of those managed fields.
HTH
No readability is not my only concern. I have a lot of calculations already coded, the new method seems less intuitive and if i remove the private variables they are will need to be recoded and some of the calculations are quite complex. the thought is overwhelming. I use the propertyhaschanged watch (including child collections) to trigger these calculations, so how do i trigger them now.
When is Rocky publishing the VB.Net ebook for this update.
Help
Thanks
Ellie
That would be good if I knew how to integrate it. If an example could be given (with the appropriate VB.NET code) I would greatly appreciate it.
Thanks
Ellie
Copyright (c) Marimer LLC