在 WCF 中序列化时不包含 IComparable
我有一个在服务器端填写的列表。它是一个“User”列表,它实现了 IComparable。 现在,当 WCF 序列化数据时,我猜它不包括 CompareTo 方法。这是我的对象类:
[DataContract]
public class User : IComparable
{
private string e164, cn, h323;
private int id;
private DateTime lastActive;
[DataMember]
public DateTime LastActive
{
get { return lastActive; }
set { laatstActief = value; }
}
[DataMember]
public int Id
{
get { return id; }
set { id = value; }
}
[DataMember]
public string H323
{
get { return h323; }
set { h323 = value; }
}
[DataMember]
public string Cn
{
get { return cn; }
set { cn = value; }
}
[DataMember]
public string E164
{
get { return e164; }
set { e164 = value; }
}
public User()
{
}
public User(string e164, string cn, string h323, DateTime lastActive)
{
this.E164 = e164;
this.Cn = cn;
this.H323 = h323;
this.LastActive= lastActive;
}
[DataMember]
public string ToStringExtra
{
get
{
if (h323 != "/" && h323 != "")
return h323 + " (" + e164 + ")";
return e164;
}
set { ;}
}
public override string ToString()
{
if (Cn.Equals("Trunk Line") || Cn.Equals(""))
if (h323.Equals(""))
return E164;
else
return h323;
return Cn;
}
public int CompareTo(object obj)
{
User user = (User)obj;
return user.LastActive.CompareTo(this.LastActive);
}
}
是否可以使用 CompareTo 方法来到达客户端? 正如我尝试的那样,放置 [DataMember] 并不是解决方案(我知道......)。
提前致谢。
I have a list i'm filling at server side. It's a list of "User", which implements IComparable.
Now when WCF is serializing the data, i guess it's not including the CompareTo method. This is my Object class :
[DataContract]
public class User : IComparable
{
private string e164, cn, h323;
private int id;
private DateTime lastActive;
[DataMember]
public DateTime LastActive
{
get { return lastActive; }
set { laatstActief = value; }
}
[DataMember]
public int Id
{
get { return id; }
set { id = value; }
}
[DataMember]
public string H323
{
get { return h323; }
set { h323 = value; }
}
[DataMember]
public string Cn
{
get { return cn; }
set { cn = value; }
}
[DataMember]
public string E164
{
get { return e164; }
set { e164 = value; }
}
public User()
{
}
public User(string e164, string cn, string h323, DateTime lastActive)
{
this.E164 = e164;
this.Cn = cn;
this.H323 = h323;
this.LastActive= lastActive;
}
[DataMember]
public string ToStringExtra
{
get
{
if (h323 != "/" && h323 != "")
return h323 + " (" + e164 + ")";
return e164;
}
set { ;}
}
public override string ToString()
{
if (Cn.Equals("Trunk Line") || Cn.Equals(""))
if (h323.Equals(""))
return E164;
else
return h323;
return Cn;
}
public int CompareTo(object obj)
{
User user = (User)obj;
return user.LastActive.CompareTo(this.LastActive);
}
}
Is it possible to get the CompareTo method to reach the client?
Putting [DataMember] isn't the solution as i tried it ( i know...).
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

发布评论
评论(4)
~没有更多了~
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
您不需要实施比较。
您也可以使用委托对列表进行排序,而无需类中的 icomparable。尝试以下代码。
您可以直接在客户端中使用它。
You do not need to implement comparable.
You can use delegates to sort a list as well, without the icomparable in the class. Try following code.
You can use this directly in your client.