我首先使用Entity Framework Code.我有一个简单的模型:
public class Variable
{
public string Name { get; set; }
public int Id { get; set; }
public IList<string> TextOptions
{
get;
set;
}
}
Run Code Online (Sandbox Code Playgroud)
我遇到了属性TextOptions类型的问题List<String>.
当我尝试在Entity Framework中执行此操作时,它不会映射.
我在这里找到了一个解决方案(stackoverflow)来解决我的问题.我基本上修改了我的类,以便它获取列表并使其成为一个分隔的字符串,它会被持久化:
public class Variable : IVariable
{
public string Name { get; set; }
public int Id { get; set; }
public virtual IList<string> TextOptions
{
get
{
return _TextOptions;
}
set
{
_TextOptions = value;
}
}
private IList<string> _TextOptions;
public string TextOptionsSerialized …Run Code Online (Sandbox Code Playgroud) 我试着将组合框项源绑定到静态资源.我过度说明了我的例子,因此很容易理解我在做什么.
所以我创建了一个类
public class A : ObservableCollection<string>
{
public A()
{
IKBDomainContext Context = new IKBDomainContext();
Context.Load(Context.GetIBOptionsQuery("2C6C1Q"), p =>
{
foreach (var item in SkinContext.IKBOptions)
{
this.Add(item);
}
}, null);
}
}
Run Code Online (Sandbox Code Playgroud)
因此,该类有一个构造函数,它使用从持久化数据库中获取数据的domaincontext填充自身.我只是在这个列表上读取所以不必担心坚持回来.
在xaml中我添加了对该类的命名空间的引用,然后我将它作为usercontrol.resources添加到页面控件.
<UserControl.Resources>
<This:A x:Key="A"/>
</UserControl.Resources>
Run Code Online (Sandbox Code Playgroud)
然后我用它这个staticresource将它绑定到我的组合框项目source.in现实我必须使用datatemplate正确显示这个对象,但我不会在这里添加.
<Combobox ItemsSource="{StaticResource A}"/>
Run Code Online (Sandbox Code Playgroud)
现在,当我在设计师时,我得到错误:
无法创建"A"的实例.
如果我编译并运行代码,它运行正常.这似乎只影响xaml页面的编辑.
我究竟做错了什么?
我使用.Schedule(DateTimeOffset,Action>)的东西使用RX调度程序类.基本上我有一个可以再次安排自己的预定动作.
码:
public SomeObject(IScheduler sch, Action variableAmountofTime)
{
this.sch = sch;
sch.Schedule(GetNextTime(), (Action<DateTimeOffset> runAgain =>
{
//Something that takes an unknown variable amount of time.
variableAmountofTime();
runAgain(GetNextTime());
});
}
public DateTimeOffset GetNextTime()
{
//Return some time offset based on scheduler's
//current time which is irregular based on other inputs that i have left out.
return this.sch.now.AddMinutes(1);
}
Run Code Online (Sandbox Code Playgroud)
我的问题是关于模拟变量AmountofTime可能采用的时间量,并测试我的代码按预期行为,并且仅触发按预期调用它.
我已经尝试推进测试调度程序在代理中的时间,但这不起作用.我编写的代码示例不起作用.假设GetNextTime()只是安排一分钟.
[Test]
public void TestCallsAppropriateNumberOfTimes()
{
var sch = new TestScheduler();
var timesCalled = 0;
var variableAmountOfTime = () =>
{
sch.AdvanceBy(TimeSpan.FromMinutes(3).Ticks); …Run Code Online (Sandbox Code Playgroud)