【问题标题】:How do I prevent DDay.ical ics files from repeating duplication events during SerializeToString function call如何防止 DDay.ical ics 文件在 SerializeToString 函数调用期间重复重复事件
【发布时间】:2011-08-18 16:20:10
【问题描述】:

希望有人可以提供帮助。将 DDay.iCal 版本 1.0.1.490 与 .net 版本 2 一起使用,我在调用 SerilizeToString 方法后得到重复的事件事件。

示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDay.iCal;
using DDay.iCal.Serialization.iCalendar;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            iCalendar iCal = new iCalendar();
            Event evt = iCal.Create<Event>();
            Uri eventLink = new Uri("http://middlebury.edu";);
            evt.IsAllDay = false;

           evt.Start = new iCalDateTime(DateTime.Parse("2011-08-11"));
           evt.Duration = new TimeSpan(2, 0, 0);
           evt.Location = "Test";
           evt.Summary = "Breakfast";
           evt.Url = eventLink;
           evt.Description = "Sausage Links" + "\n" + "Pancakes" + "\n";

          iCal.Events.Add(evt);

          iCalendarSerializer serializer = new iCalendarSerializer(iCal);

          string result = serializer.SerializeToString(iCal);
      }
   }
}

【问题讨论】:

    标签: serialization icalendar dday


    【解决方案1】:

    Event evt = iCal.Create&lt;Event&gt;() 行创建一个新事件,将其添加到日历的事件集合中,然后返回它。稍后,您手动将相同的事件添加到日历的事件集合中:iCal.Events.Add(evt)

    我也在做同样的事情,没有意识到 Create() 方法将事件添加到日历中。要么使用标准构造函数来初始化事件Event evt = new Event(),要么将手动Add() 删除到日历的事件集合中。

    【讨论】:

    • 谢谢 - 这就像一个魅力,事后看来非常有意义。
    • 谢谢!正是我需要的!
    猜你喜欢
    • 1970-01-01
    • 2017-04-14
    • 2017-12-09
    • 2016-02-03
    • 2023-03-12
    • 1970-01-01
    • 2012-08-01
    • 2010-12-17
    • 1970-01-01
    相关资源
    最近更新 更多