.net - 如何在 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), 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 本身并不处理颜色(请参见此处)。我如何实现这一目标?
解决方案
尼玛德。想通了。我只是把它放在我初始化数据库的代码附近:
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
)
推荐阅读
- google-colaboratory - Model.fit 在 Tensorboard 示例中停止
- php - 来自 2 个表的电话品牌和电话型号的 Laravel 嵌套查询
- node.js - 填充返回整个父文档
- python - 使用 iloc 函数循环数据帧
- wordpress - Wordpress 中的联系表格 7:如何设置让人们在发送前查看他们输入的内容?
- mysql - 按自定义优先级选择列值
- flutter - 如何在 Flutter 中为视频添加水印?
- javascript - 代理和 ServerParseError 的 GraphQL 错误
- java - java链表中节点的引用传递
- python - 如何在 python 中为基于文本的冒险游戏创建保存系统?