I'll be interested to hear what others think of this idea.
My first reaction is that this is a really good idea.
Here's a broader (and maybe more dangerous) alternative that also seems interesting:
using (new DirectAccess(_project))
{
_project.Id = dto.Id;
_project.Name = dto.Name;
_project.Started = dto.Started;
// ...
}
The using block seems cleaner than setting the property manually.
The drawback to this approach is (at least as I'm showing it) that external code could use it to cheat, and that could be bad.
But it could be protected only like this:
using (this.BypassPropertyChecks)
{
Id = dto.Id;
Name = dto.Name;
Started = dto.Started;
// ...
}
Same idea, but using a protected BypassPropertyChecks property so it is only available inside the object.
RockfordLhotka:My first reaction is that this is a really good idea.
RockfordLhotka:The using block seems cleaner than setting the property manually.
Yes it is a lot cleaner and also makes sure that the object is never left in "Bypass" mode should an exception occur during set or get of the property.
RockfordLhotka:The drawback to this approach is (at least as I'm showing it) that external code could use it to cheat, and that could be bad.
Hm if "DirectAccess" was internal instead of public the harm might be limited... In the case below the Id still couldn't be set from the outside.
private static PropertyInfo<Int32> IdProperty = RegisterProperty(new PropertyInfo<Int32>("Id"));
public string Id
{
get { return GetProperty<string>(IdProperty); }
private set { SetProperty<string>(IdProperty, value); }
}
My vote is for the "using" syntax. It is clean and provides nicely structured, easy to read, code.
-- Fintan
Thanks Ricky – my idea was that the property would return
an IDisposable token object – much the way the WPF data provider
infrastructure works, and pretty much exactly what you have in your example.
Rocky
Hi,
is there any plan to implement this in CSLA.NET 3.6?
Thanks,
Patrick
This is in the Windows version too. You can see the file
revisions if you click the “svn revisions” link from the bugtracker
summary page:
http://www.lhotka.net/cslabugs/edit_bug.aspx?id=70
Rocky
RockfordLhotka:This is in the Windows version too. You can see the file revisions if you click the “svn revisions” link from the bugtracker summary page:
Hi Rocky,
thanks for your answer. I can see that it's in the windows version but it seems to be missing from 3.6 Beta 2 http://www.lhotka.net/cslacvs/viewvc.cgi/tags/V3/V3-6-0-b2/cslacs/Csla/BusinessBase.cs?view=markup
Thanks,
Patrick
This feature only works one level deep right? I have an object property that returns one of three different ManagedProperties depending on the valueTypeCode stored in a 4th Property.
in pseudo code to make readalbe
Object DataValue =
Switch(Field.FieldTypeValue)
case "Number" : return DataProperty.ValueNumber;
case "Date" : return DataProperty.ValueDate;
case "String" : return DataProperty.ValueText;
If I use the ReadProperty then this starts to look like
Object DataValue =
Switch(ReadProperty<xxx>(Field).ReadProperty<yyy>(FieldTypeValue))
case "Number" : return ReadProperty(DataProperty).ReadProperty(ValueNumber);
etc.
The code looks horrible and is hard to read.
Is there a syntax that will basically use the ByPassPropertyCheck on nested managed properties?
Thanks
jack
How can you even do that? ReadProperty() is a protected member,
so you can’t write code in one object to call it in another object –
even a child object.
Rocky
That is the problem... I can't :-).
I'm looking for help/direction in how to handle this. I'm starting to think I have to go back to the child and change all my codeGen Public abc properties to internal property and ReadProperty vs. GetProperty As its only used by the Parent.
Am I making sense or babbling uselessly?
thx
jack
In general, one object shouldn’t be mucking around with
the fields of another object. That breaks encapsulation and is a major anti-pattern
for OO programming.
Instead, one object should ask other objects to do things, or
ask other objects questions to get data.
If this child property is only used by the parent, then it
should probably be internal/Friend in scope, and can just use ReadProperty() so
you never worry about authorization checks. Though why it would ever have an
authz rule if it is only for internal use I’m not sure…
Rocky
The child property is only used by the parent and creating an
internal version is what I am doing. I guess maybe I am getting too excited
about the overhead of the Read vs. Get with no authorization checks. There is
a lot of extra things going on but all the checks will process nothing.
So bottom-line is there any real overhead if there are no
rules? I have to do a bunch of these property checks each time the user tabs through
a field so limiting the overhead is very important to me.
Thx
jack
From: Rockford Lhotka [mailto:cslanet@lhotka.net]
Sent: December-02-08 4:38 PM
To: jaddington@shaw.ca
Subject: RE: [CSLA .NET] RE: CSLA.NET 3.6: ByPassPropertyChecks
In general, one object shouldn’t be mucking around with the
fields of another object. That breaks encapsulation and is a major anti-pattern
for OO programming.
Instead, one object should ask other objects to do things, or
ask other objects questions to get data.
If this child property is only used by the parent, then it
should probably be internal/Friend in scope, and can just use ReadProperty() so
you never worry about authorization checks. Though why it would ever have an
authz rule if it is only for internal use I’m not sure…
Rocky
Actually I guess I can improve on my design. I don't need to the switch/case in the parent - it should do it in the child which eliminates one level and makes more sense with the ReadProperty in the child.
jack
FrankM:There is another BusinessBase.cs under Core folder. The one Patrick provided is under Csla root defining BusinessBase, which is inherited from Csla.Core.BusinessBase.
The BypassPropertyChecksObject is created in Csla.Core.BusinessBase.
I don't know why the tag is wrong...
If you want the current stuff though, use /trunk - it includes a couple bug fixes and lots of new comments (that's my primary focus now, bug fixing and commenting).
Copyright (c) Marimer LLC