0

I am trying to serialize and deserialize a System.Drawing.Color property in LiteDb. I've read the article below, but have no idea how to implement this in code:

LiteDb Docs

Here's an example of the poco class:

Public Class mPage

    <Id(1, 1), Category("IDs"), [ReadOnly](True)>
    Public Property ID As ObjectId = ObjectId.NewObjectId

    <Id(1, 10), Category("General"), DisplayName("Design Name"), Description("Name used in the designer (short - just for identification purposes).")>
    <TypeConverter(GetType(RemoveSpaces))>      
    Public Property Name As String = ""

    <Id(15, 10), Category("General"), DisplayName("Background Color"), Description("The background color of the page.")>
    Public Property BackgroundColor As Color = Color.LightGray

End Class

LiteDb does not deal with Color natively(see here). How do I achieve this?

stigzler
  • 793
  • 2
  • 12
  • 29

1 Answers1

1

Nemmind. Figured it. I just placed this near the code where I initialise the db:

    BsonMapper.Global.RegisterType(Of Color)(Function(g) g.A & "," & g.R & "," & g.G & "," & g.B,
                                             Function(s As String)
                                                 Dim c() As String = s.Split(",")
                                                 Return Color.FromArgb(c(0), c(1), c(2), c(3))
                                             End Function
                                             )
stigzler
  • 793
  • 2
  • 12
  • 29