.net 如何在LiteDb中设置自定义类型?
我正在尝试序列化和反序列化LiteDb中的System.Drawing.Color属性。我已经阅读了下面的文章,但不知道如何在代码中实现这一点: 以下是poco类的一个示例:.net 如何在LiteDb中设置自定义类型?,.net,bson,litedb,.net,Bson,Litedb,我正在尝试序列化和反序列化LiteDb中的System.Drawing.Color属性。我已经阅读了下面的文章,但不知道如何在代码中实现这一点: 以下是poco类的一个示例: Public Class mPage <Id(1, 1), Category("IDs"), [ReadOnly](True)> Public Property ID As ObjectId = ObjectId.NewObjectId <Id(1, 10), Categor
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
公共类mPage
公共属性ID为ObjectId=ObjectId.NewObjectId
公共属性名称为String=“”
公共属性背景颜色为Color=Color.LightGray
末级
LiteDb本机不处理颜色()。我怎样才能做到这一点呢?。我明白了。我只是把它放在初始化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
)