我正在使用 Spring.NET 来配置一些对象,并且我已经编写了一个 FactoryObject 来使配置 Quartz.NET 日历变得可以接受。
它有一个如下所示的属性,当然我们希望使用 Spring.NET 进行配置
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Quartz.Impl.Calendar;
using Spring.Objects.Factory;
namespace My.Package.TaskExecutorDemo
{
/// <summary>
/// TODO:
/// </summary>
public class WeeklyCalendarFactoryObject : WeeklyCalendar, IFactoryObject
{
private ISet<DayOfWeek> _daysOfWeek = new HashSet<DayOfWeek>();
public ISet<DayOfWeek> DaysOfWeekExcluded
{
get { return _daysOfWeek; }
set
{
if (value == null)
{
throw new ArgumentNullException("DaysOfWeekExcluded");
}
_daysOfWeek = value;
}
}
//Everything else ...
}
}
它由以下对象定义配置。
<object id="weeklyCalendar" type="My.Package.TaskExecutorDemo.WeeklyCalendarFactoryObject, TaskExecutorDemo">
<property name="DaysOfWeekExcluded">
<set element-type="System.DayOfWeek, mscorlib">
<value>Friday</value>
<value>Saturday</value>
<value>Sunday</value>
</set>
</property>
</object>
但是在启动时会引发以下异常:
Spring.Objects.Factory.ObjectCreationException:在“配置 [C:\Users\username\some\path\TaskExecutorDemo\bin\Debug\TaskExecutorDemo.exe.Config#spring/objects] 第 7 行中创建名称为“weeklyCalendar”的对象时出错':对象初始化失败:无法将 System.Collections.Generic.HashSet`1[System.DayOfWeek]' 类型的对象转换为类型 'Spring.Collections.ISet'。
System.InvalidCastException:无法将“System.Collections.Generic.HashSet`1[System.DayOfWeek]”类型的对象转换为“Spring.Collections.ISet”类型。
但我没有Spring.Collections.ISet
在我的代码中引用任何地方。如何让 Spring.NETISet
正确配置我的属性?