Custom Nullable Class

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I developed a custom file attachments class for an application and from the
UI the user can choose to upload attachments. There is a add method that
takes a FileAttachmentCollection object, runs a for each, and uploads each
attachment. I was thinking that it would be nice to allow it to be Nullable
if they happen not choose to upload attachments when submitting data. When I
try Public Sub Add(attachments As Nullable(Of FileAttachmentCollection) I
get: Type argument 'BusinessLogicLayer.FileAttachmentCollection' does not
satisfy the 'Structure' constraint for type parameter 'T'. I am doing the
following for my collection.

Public Class FileAttachmentCollection
Inherits System.Collections.ObjectModel.Collection(Of FileAttachment)
End Class

Any thoughts on how to correct this error?


Is there an easy way to fix this?
 
Nick,
Any thoughts on how to correct this error?


Is there an easy way to fix this?

Yes, just change the signature to

Public Sub Add(attachments As FileAttachmentCollection)

Since FileAttachmentCollection is a Class, it's already nullable.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top