C# Byte Array (byte[]) as a BO property

C# Byte Array (byte[]) as a BO property

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


jervit posted on Friday, November 24, 2006

Hi

Have any of you had experience using byte[] in C# as a property for saving file attachments?

I have this property in a BO

public byte[] BinaryForm

{

   get

      {

         CanReadProperty("BinaryForm", true);

         return _binaryForm;

      }

   set

      {

         CanWriteProperty("BinaryForm", true);

         if (!_binaryForm.Equals(value))

         {

            _binaryForm = value;

             PropertyHasChanged("BinaryForm");

         }

      }

}

I am experiencing a NullReferenceException when assigning to it in a WinForm app like this

         _verification.Attachments[e.RowIndex].BinaryForm = binaryForm;

The same verification BO is also used as bindingdatasource for a datagridview.

Thanks for any help.

Michael Hildner replied on Saturday, November 25, 2006

Yeah,

Make sure to initialize your variable. e.g. private byte[] _binaryForm = new byte[42]. Otherwise it will be null when it does the .Equals check.

Mike

Fabio replied on Saturday, November 25, 2006

            set
            {
                CanWriteProperty("
BinaryForm", true);
                if ((
_binaryForm==null && value!=null) || (!_binaryForm.Equals(value)))
                {
                    _
binaryForm= value;
                    PropertyHasChanged("
BinaryForm");
                }
            }
But...
If you don't have a special matter you can use
            set
            {
                CanWriteProperty("
BinaryForm", true);
                _binaryForm= value;
                PropertyHasChanged("
BinaryForm");
            }
Bye.
Fabio.

Copyright (c) Marimer LLC