3.5 Changes

3.5 Changes

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


SouthSpawn posted on Friday, April 11, 2008

It is saying that the "PropertyChanged" and "CanReadProperty" methods are now obsolete.
What should I use instead?
 
Or should I just get rid of them all together.
 
Thanks,
Mark

JoeFallon1 replied on Friday, April 11, 2008

I am pretty sure that only the parameterless versions of those methods were deprecated.

They relied on a Stack walk that proved to be unreliable.

Since I use Codesmith I always used the version where you passed in the property name as a String. That is the recommended step to take if you want to keep the upgrade simple.

Alternatively, you can use the new Property constructs that Rocky is providing that use 30% less code and are automatically managed by CSLA. I have not had time to dig into them yet and they have not been proven to work in all scenarios yet. I'm not saying they don't work - it is just that there is no historical data from their use in production applications yet. So I think that when I upgrade I will use the older style properties until there is more feedback.

Joe

 

MrPogo replied on Friday, April 11, 2008

So the way it should look is:

private int _id;

public int Id

{

      get

      {

            CanReadProperty("Id"); 

            return _id;

      }

      set

   {

         CanWriteProperty("Id");

         if(....

         {

               _id = value;

               PropertyChanged("Id");

         }

   }

}

 

sergeyb replied on Friday, April 11, 2008

Not quite.  You need another parameter to throw an exception if rights check fails.

 

private int _id;

public int Id

{

      get

      {

            CanReadProperty("Id", true); 

            return _id;

      }

      set

   {

         CanWriteProperty("Id", true);

         if(....

         {

               _id = value;

               PropertyChanged("Id");

         }

   }

}

 

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: MrPogo [mailto:cslanet@lhotka.net]
Sent: Friday, April 11, 2008 11:18 AM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] 3.5 Changes

 

So the way it should look is:

private int _id;

public int Id

{

      get

      {

            CanReadProperty("Id"); 

            return _id;

      }

      set

   {

         CanWriteProperty("Id");

         if(....

         {

               _id = value;

               PropertyChanged("Id");

         }

   }

}

 



SouthSpawn replied on Saturday, April 12, 2008

I changed my code to the following below.

Public
Property State() As CountriesStates.State Implements Interfaces.IAddress.State
   Get
         
   CanReadProperty("State")
            
            
Return _state
   End Get

   Set(ByVal value As CountriesStates.State)
            PropertyHasChanged(
"State")

         _state = value
   
End Set
End Property

JonnyBee replied on Monday, April 14, 2008

You should NOT call PropertyHasChanged before you set the actual value.

That would cause your validation rules to run before the new value is entered in your BO.

Correct sequence:
- set the new property value
- call PropertyHasChanged

/jonny

Copyright (c) Marimer LLC