【发布时间】:2017-01-21 02:56:30
【问题描述】:
我对 Xamarin 很陌生,我正在尝试为 Android/iOS 制作一个应用程序。我正在尝试使用 putExtra 发送一个类,因此我尝试通过添加 ISerializable 接口使该类可序列化,但是每当我尝试这样做时,我都需要实现 Handle() 和 Dispose() 方法。我不确定如何处理这些方法,所以它们有一个 NotImplementedException。
当我尝试进行下一个活动时,我得到 NotImplementedException(很可能来自句柄或处置)。我想知道我的类的实现是否有问题。
这是 Event 类(我尝试将其发送到下一个 Activity):
public class Event : Object, ISerializable
{
private long id;
private string name;
private string description;
private double latitude = 0;
private double longitude = 0;
private User author;
private List<User> participants;
private List<EventDate> eventDates;
public Event(long id, string name, string description, double latitude, double longitude, User author, List<User> participants, List<EventDate> eventDates)
{
this.id = id;
this.name = name;
this.description = description;
this.latitude = latitude;
this.longitude = longitude;
this.author = author;
this.participants = participants;
this.eventDates = eventDates;
}
public Event(long id, string name, string description, User author)
{
this.id = id;
this.name = name;
this.description = description;
this.author = author;
this.participants = new List<User>();
this.eventDates = new List<EventDate>();
}
public long Id
{
get { return id; }
}
public string Name
{
get { return name; }
}
public string Description
{
get { return description; }
}
public double Latitude
{
get { return latitude; }
}
public User Author
{
get { return author; }
}
public List<User> Participants
{
get { return participants; }
}
public List<EventDate> EventDates
{
get { return eventDates; }
}
public IntPtr Handle
{
get
{
throw new NotImplementedException();
}
}
public EventDate getBestDate()
{
EventDate bestDate = null;
foreach (EventDate date in eventDates)
{
if (bestDate == null || date.AvailableUsers.Count > bestDate.AvailableUsers.Count)
{
bestDate = date;
}
}
return bestDate;
}
public void addParticipant(User participant)
{
this.participants.Add(participant);
}
public void Dispose()
{
throw new NotImplementedException();
}
}
这个类在 (Portable) 项目中,而不是在 .Droid 项目中,因为我在 iOS 中也需要它。
有人可以告诉我我做错了什么或建议替代方法吗?
提前致谢。
【问题讨论】:
标签: c# android xamarin serializable