unnecessary String.IsNullOrEmpty tests in DataWrapper Model

Oct 10, 2009 at 10:05 PM

Hi,

Cinch is a really great work.

Congratulations..

But I have a little improvement for string properties in a DataWrapper. With this little snippet it isn't anymore necessary to test each string property separately.

<font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">



static

</font></font></font><font face="Consolas" size="2" color="#0000ff"><font face="Consolas" size="2" color="#0000ff">

 

</font></font><font face="Consolas" size="2" color="#0000ff">

 

</font>

PropertyChangedEventArgs dataValueChangeArgs = ObservableHelper.CreateArgs<DataWrapper<T>>(x => x.DataValue);

public T DataValue
{
   get { return datavalue; }
   set
   {
       
if(value.GetType() == typeof(string)) {
          
if(value is DBNull || value == null)
          {
             dataValue = (T)(object)String.Empty;
          }
          else
          {
            dataValue = (T)(object)(value.ToString());
          }
       }
       else
       {
           dataValue = value;
       }
       
NotifyPropertyChanged(dataValueChangeArgs);
       NotifyParentPropertyChanged();
  }
}

Any remarks?

Bye Andreas

Coordinator
Nov 5, 2009 at 2:38 PM

Thanks, Ill look at maybe including this when I have some time again. There are a few things to fix. Very minor things.

Coordinator
May 4, 2010 at 8:23 AM
Decided not to include this, as it seemed to specific when T in DataWrapper<T> could be anything.