我有以下界面:
public interface IValidationSystem<T>
{
IAsyncEnumerable<ValidationResult> ValidateAsync(T obj);
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试以这种方式实现它:
public class Foo
{ }
public class Bar
{ }
public class BarValidationSystem : IValidationSystem<T>
{
public async IAsyncEnumerable<ValidationResult> ValidateAsync(Bar bar)
{
var foo = await GetRequiredThingAsync();
return GetErrors(bar, foo).Select(e => new ValidationResult(e)).ToAsyncEnumerable();
}
private static IEnumerable<string> GetErrors(Bar bar, Foo foo)
{
yield return "Something is wrong";
yield return "Oops something else is wrong";
yield return "And eventually, this thing is wrong too";
}
private Task<Foo> GetRequiredThingAsync()
{
return Task.FromResult(new …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个受密码保护的SQLite数据库,以便在使用Entity Framework Core的WPF应用程序中使用它.
我找到了如何从现有的SQLite DB(数据库第一种方法)生成我的DbContext和实体,但我无法使用受密码保护的DB.
实际上,我甚至不确定如何创建受密码保护的SQLite DB.加密数据库和受密码保护的数据库有什么区别?
我正在使用IoC Container Unity,根据文档,将此xmlns属性添加到"unity"部分必须允许Visual Studio执行一些Intellisense操作:
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
</configSections>
[..]
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
[..]
</unity>
</configuration>
Run Code Online (Sandbox Code Playgroud)
实际上,它不起作用.似乎资源已被(重新)移动.你知道新的链接吗?
我知道有很多关于该错误的问题(1、2、3、4、5等),但我找不到可以解释此错误原因并适合我的情况的问题。如果我错过了,请告诉我!
首先,我ItemsSource使用自定义类(不是ObservableCollection或任何其他 .NET 内置可观察集合)绑定到我的 DataGrid 。在向您展示它的代码之前,让我解释一下我的想法(我的假设可能是错误的)。
在我看来,要可绑定,集合必须至少实现IEnumerable和INotifyCollectionChanged。IEnumerable 以便视图获取要显示的项目(感谢该GetEnumerator方法)和 INotifyCollectionChanged 以便视图知道集合上的更改。
所以我最终上了这门课:
public class ObservableDictionary<TKey, TValue> : IDictionary<TKey, TValue>, IEnumerable<TValue>, INotifyCollectionChanged
{
#region fields
private IDictionary<TKey, TValue> _innerDictionary;
#endregion
#region properties
public int Count { get { return _innerDictionary.Count; } }
public ICollection<TKey> Keys { get { return _innerDictionary.Keys; } }
public ICollection<TValue> Values { get { return _innerDictionary.Values; } } …Run Code Online (Sandbox Code Playgroud) 我在图书馆遇到了一个意想不到的问题NewtonSoft.Json。看起来它会向没有小数部分的十进制值添加尾随 0:
JsonConvert.SerializeObject(1m)
Run Code Online (Sandbox Code Playgroud)
将返回以下字符串:"1.0"。
虽然在很多情况下这不是问题,但就我而言,我确实关心用户提供的精度。如果用户输入1,我需要存储1在我的数据库中。如果他提供了1.0那么我需要存储1.0。
我正在使用该库的最后一个版本:12.0.3,但我尝试使用所有以前的主要版本到9.0.1,它们都产生相同的结果。
我看到了几个关于库删除尾随 0 的问题(报告为错误,在版本 11.X 中修复),但没有看到关于添加 1 的问题。
这是我应该报告的错误吗?我怎样才能覆盖这个默认行为?