【发布时间】:2017-05-09 18:34:13
【问题描述】:
我有一个小型测试项目,用于从服务器检查应用程序版本并提示用户更新。除了我无法将System.Version 类型保存到My.Settings 之外,一切正常。 (我想保存新版本,以防用户要求不再提醒。)
现在,我知道我可以将 Version 保存为字符串并来回转换 - 我已经这样做以解决这个问题 - 但由于 System.Version 列在可用的设置数据类型中,我认为它应该可以工作.但不是保存版本,它只是保存一个没有值的 XML 条目“版本”(请参阅下文)。
我正在使用 VB.NET、VS 2013、.NET 4。
下面是一些代码:
Settings.Designer.vb
<Global.System.Configuration.UserScopedSettingAttribute(), _
Global.System.Diagnostics.DebuggerNonUserCodeAttribute()> _
Public Property DoNotRemindVersion() As Global.System.Version
Get
Return CType(Me("DoNotRemindVersion"),Global.System.Version)
End Get
Set
Me("DoNotRemindVersion") = value
End Set
End Property
作业示例
If My.Settings.DoNotRemind Then My.Settings.DoNotRemindVersion = oVersion.NewVersion
(oVersion.NewVersion 的类型为 System.Version。)
保存在 user.config 中
<setting name="DoNotRemindVersion" serializeAs="Xml">
<value>
<Version xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
</value>
</setting>
那么,我做错了什么?我已经阅读了一些关于必须序列化类以将它们保存到用户设置的帖子,但这是一个简单的版本号,从表面上看,我希望它是受支持的数据类型。
【问题讨论】:
-
我尝试添加
Version类型的设置并在项目属性中设置它的值,但我希望工作的值都没有实际工作,所以我猜它是只是不可能。
标签: vb.net my.settings system.version