View unanswered posts | View active topics It is currently 2020-05-26 6:48



This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
 设置的元素id为整数类型,但是序列化再反序列化后为string类型? 
Author Message
新手上路

Joined: 2014-04-17 13:34
Posts: 11
Post 设置的元素id为整数类型,但是序列化再反序列化后为string类型?
public interface IData : IClient
{
IList<IData> Children { get; }
int ChildrenCount { get; }
bool HasChildren { get; }
string Icon { get; set; }
object ID { get; }
string Name { get; set; }
IData Parent { get; set; }
string ToolTip { get; set; }


<Data Type="TWaver.Node" Ref="1" ID="17">
<P N="Name"><![CDATA[RDCoreSwitch]]></P>
<P N="Icon">switchImage</P>
<P N="Parent" Ref="0" />
<P N="Image">switchImage</P>
<P N="Location" X="307.588200889132" Y="288.051325080824" />
<P N="Width">100</P>
<P N="Height">15</P>
</Data>

object ID在元素添加时被设置成了int类型,但是序列化再反序列化后就变成了string类型,由于程序中的很多数据结构都用了int类型,导致反序列化回来就出问题了,请问是否可以把id设置成序列化整数的类型。本来想反序列化回来后,再把数据强制转化一下,可是它是个只读属性。(WPF中使用),解决不了的话,我是否被逼把现在使用的所有内部数据结构的id类型都改为string类型。


2014-05-08 14:39
Profile
TWaver开发组
User avatar

Joined: 2009-04-20 18:37
Posts: 3115
Post Re: 设置的元素id为整数类型,但是序列化再反序列化后为string类型?
试试程序启动后,在new Data之前,调用
SerializationSettings.RegisterGlobalProperty("ID", Consts.TYPE_INT, false, true); //注意最后一个参数必须为true,这样才能覆盖默认设置
默认是:
SerializationSettings.RegisterGlobalProperty("ID", Consts.TYPE_STRING, false, false);

还有一点要注意,不能调用默认构造函数,因为默认构造函数用的string作为id。


2014-05-09 10:39
Profile
Display posts from previous:  Sort by  
This topic is locked, you cannot edit posts or make further replies.   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron