Serializasation
Jeg har følgende klasse som jeg ønsker at putte i en database, hvilket betyde Serializasation. Fejle pt er "Objektet skal implementere IConvertible."Imports Microsoft.VisualBasic
Namespace Competitions
Public Enum QuestionType
DropDown
End Enum
<Serializable()> _
Public Class Answer
Private _answer As String = ""
Public Property Text() As String
Get
Return _answer
End Get
Set(ByVal value As String)
_answer = value
End Set
End Property
' ==========
' Constructors
' ==========
Public Sub New(ByVal Answer As String)
Me.Text = Answer
End Sub
End Class
<Serializable()> _
Public Class Question
Private _answers As List(Of Answer) = New List(Of Answer)
Private _type As QuestionType
Public Property Type() As QuestionType
Get
Return _type
End Get
Set(ByVal value As QuestionType)
_type = value
End Set
End Property
Private _question As String
Public Property Text() As String
Get
Return _question
End Get
Set(ByVal value As String)
_question = value
End Set
End Property
Public WriteOnly Property addAnswer() As String
Set(ByVal value As String)
_answers.Add(New Answer(value))
End Set
End Property
Public ReadOnly Property GetAnswers() As List(Of Answer)
Get
Return _answers
End Get
End Property
' ==========
' Constructors
' ==========
Public Sub New(ByVal Question As String, ByVal Type As QuestionType)
Me.Text = Question
Me.Type = Type
End Sub
End Class
<Serializable()> _
Public Class Competition
Private _questions As List(Of Question) = New List(Of Question)
Private _name As String
Public Property Name() As String
Get
Return _name
End Get
Set(ByVal value As String)
_name = value
End Set
End Property
Private _headline As String = ""
Public Property Headline() As String
Get
Return _headline
End Get
Set(ByVal value As String)
_headline = value
End Set
End Property
Private _language As String = "dk"
Public Property Language() As String
Get
Return _language
End Get
Set(ByVal value As String)
_language = value
End Set
End Property
Private _teaser As String = ""
Public Property Teaser() As String
Get
Return _teaser
End Get
Set(ByVal value As String)
_teaser = value
End Set
End Property
Private _body As String = ""
Public Property Body() As String
Get
Return _body
End Get
Set(ByVal value As String)
_body = value
End Set
End Property
Private _publish As DateTime
Public Property Publish() As DateTime
Get
Return _publish
End Get
Set(ByVal value As DateTime)
_publish = value
End Set
End Property
Private _finish As DateTime
Public Property Finish() As DateTime
Get
Return _finish
End Get
Set(ByVal value As DateTime)
_finish = value
End Set
End Property
Public WriteOnly Property addQuestion() As Question
Set(ByVal value As Question)
_questions.Add(value)
End Set
End Property
Public ReadOnly Property Questions() As List(Of Question)
Get
Return _questions
End Get
End Property
' ==========
' Constructors
' ==========
Public Sub New()
End Sub
End Class
End Namespace