给定以下两行,XCode 显示第二行错误Cannot convert value of type 'String' to expected argument type 'OSLogMessage': 。
logger.info("Device found:")
logger.info(String(describing: device))
Run Code Online (Sandbox Code Playgroud)
有人可以解释为什么显示此错误吗?在这两种情况下,参数都是 String 类型。(我猜)
目前,我通过使用字符串插值来解决此问题。但这感觉不对。有没有比以下更好的方法:
logger.info("\(String(describing: device))")
Run Code Online (Sandbox Code Playgroud) 我正在使用以下代码行来查询SQLite数据库中给定表的一些数据(平台是WP81,但我想这并不重要).
return await Connection.Table<WorkDay>().Where(wd => wd.Date >= @from && wd.Date <= to).ToListAsync().ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)
当我执行我的代码时,我在Where子句中得到一个NullReferenceException.当我删除where条件时一切正常.
return await Connection.Table<WorkDay>().ToListAsync().ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)
为了确保我的表中的所有条目都有效并且Date列中没有空值,我使用SQL工具查看SQLite数据库.
因为我无法调试lambda表达式,所以我有点坚持如何在这里找到问题.我的假设是由于异步处理而出现问题.
编辑: 这是异常的确切堆栈跟踪
{System.NullReferenceException: Object reference not set to an instance of an object.
at SQLite.Net.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
at SQLite.Net.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
at SQLite.Net.TableQuery`1.CompileExpr(Expression expr, List`1 queryArgs)
at SQLite.Net.TableQuery`1.GenerateCommand(String selectionList)
at SQLite.Net.TableQuery`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at SQLite.Net.Async.AsyncTableQuery`1.<ToListAsync>b__0()
at System.Threading.Tasks.Task`1.InnerInvoke()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at …Run Code Online (Sandbox Code Playgroud) 在下面的C#片段中,我重写了该==方法._type是一些类型short.所以我实际上说当两个WorkUnitTypes相同时,两个short是相同的.
public static bool operator ==(WorkUnitType type1, WorkUnitType type2)
{
if (type1 == null || type2 == null)
return false;
return type1._type == type2._type;
}
Run Code Online (Sandbox Code Playgroud)
因为R#警告我,并且完全清楚为什么,type1/ type2可能是null,我试图用if上面的陈述来捕捉它.
现在我得到了一个StackOverflowException完全有意义的东西,因为我实际上是在调用覆盖.
问题:如何编写此方法"正确".我怎样才能抓住那个type1或type2可能的案例null?
我最好的猜测:也许我只是==在这里滥用,并且应该使用Equals覆盖来检查是否相等.但我仍然认为问题存在.那么我在推理中的错误在哪里?
当我尝试在javascript中的任何地方设置断点时,我遇到了断点在Firefox Developer Edition中移动到文件末尾的行为.

有时在重新启动PC之后或第二天它正在运行,但我不确定某些代码是否会导致此问题,或者这是否是Firefox Developer Edition中的错误.
使用MVVMLight,我有一些在可移植项目中声明的服务接口以及Windows Phone项目(WP8.1 SL)中的相应实现.注册我SimpleIoc.Default.Register在类中的Application_Launching方法中使用的实现App.
public partial class App : Application
{
...
private async void Application_Launching(object sender, LaunchingEventArgs e)
{
...
// add some platform specific services to the IOC container
SimpleIoc.Default.Register<INavigationService, NavigationServiceWP>(true);
SimpleIoc.Default.Register<ISettingsService, SettingsService>(true);
SimpleIoc.Default.Register<IThemeService, ThemeService>(true);
SimpleIoc.Default.Register<IGeofenceService, GeofenceService>(true);
SimpleIoc.Default.Register<IVersionService, TrialInformation>(true);
SimpleIoc.Default.Register<IPhoneService, PhoneServices>(true);
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
视图模型定位器位于可移植项目中,并在静态构造函数中将所有视图模型注册到IOC容器,就像文档所述.
static ViewModelLocator()
{
...
SimpleIoc.Default.Register<TagColorViewModel>();
...
}
Run Code Online (Sandbox Code Playgroud)
这TagColorViewModel是这些模型之一.它会在显示相应视图之前收到消息.例如,单击标签以更改其颜色然后MessengerInstance.Send使用,然后导航服务用于导航到标签颜色更改视图.
// TagViewModel
private void ChangeColor()
{
MessengerInstance.Send(Tag, TagColorViewModel.MessengerToken.SetTag);
_navigationService.Navigate("/UI/Tagging/TagColor.xaml");
}
Run Code Online (Sandbox Code Playgroud)
此消息接收器已在构造函数中注册.
// TagColorViewModel
[PreferredConstructor] …Run Code Online (Sandbox Code Playgroud) 简介:在基于SQLite.net的SQLite数据库中(在WP8.1 SL上,但这无关紧要),我正在基于给定对象添加数据。该对象包含一个名为的自定义类型Date。到目前为止,我不将该属性存储在数据库中,而是使用另一个属性作为解决方法。
[Ignore]
public Date Date { get; set; }
[PrimaryKey]
public DateTime DateInternal
{
get { return Date.ToDateTime(); }
set { Date = new Date(value); }
}
Run Code Online (Sandbox Code Playgroud)
虽然效果很好,但我觉得这不是最好的方法。
实际问题:我该如何改善。即,我如何Date直接存储序列化版本。它应该以某种方式Date可以用作主键。对于我而言,将所有属性都放在Date表的单个列中并不重要。我只想将Date自己存储在一列中。
目前的研究:在尝试向Google寻求答案的过程中,我偶然发现了SQLite.net的ISerializable界面,但由于该serialize方法只有一种方法而没有deserialize方法,因此我不确定如何使用它。
namespace SQLite.Net
{
public interface ISerializable<T>
{
[PublicAPI]
T Serialize();
}
}
Run Code Online (Sandbox Code Playgroud) 当使用添加的SQLite构建UWP应用时,我会收到约40条警告,如下所示(只是方法名称更改了)(添加了一些新行以提高可读性)。该配置被设置为释放。我没有在调试模式下收到任何这些消息。
C:\Program Files (x86)\MSBuild\Microsoft\.NetNative\ARM\ilc\IlcInternals.targets(936,5):
warning : ILTransform_0000:
MCG : warning MCG0006:
Unresolved P/Invoke method 'Open!sqlite3' in assembly
'SQLite.Net.Platform.WinRT, Version=3.1.0.0, Culture=neutral, PublicKeyToken=null'
because it is not available in UWP applications. Please either use an another API ,
or use [DllImport(ExactSpelling=true) to indicate that you understand the
implications of using non-UWP application APIs.
Run Code Online (Sandbox Code Playgroud)
根据许多教程,我在项目中有以下参考。
SQLite for Windows Universal Platform通过sqlite.org的sqlite-uwp-3120200.vsix文件安装Visual C++ 2015 Runtime for Universal Windows Platform Apps (尝试使用此扩展名和不使用此扩展名,因为某些教程是否需要添加此扩展名有所不同)SQLite.Net-PCL (v3.1.1)通过NuGet安装其目标版本和最低版本为10586。由于它是在发布模式下构建的,因此启用了本机工具链。
有谁知道此警告消息的含义以及如何解决?
我在几个场景中使用了 dotnet core 3.1 Web 应用程序中的HttpContextfrom 。IHttpContextAccessor它总是按照我的预期设置。
但是,当注入Razor 组件HttpContext时,始终为 null 。IHttpContextAccessor
@inject IHttpContextAccessor HttpContextAccessor
<div>...</div>
@code {
protected override async Task OnInitializedAsync()
{
// here, HttpContextAccessor.HttpContext == null
}
public string GetSomeInfo()
{
// here, HttpContextAccessor.HttpContext == null
}
}
Run Code Online (Sandbox Code Playgroud)
我已经像这样IHttpContextAccessor添加了Startup.cs/ConfigureServices()
services.AddHttpContextAccessor();
Run Code Online (Sandbox Code Playgroud)
为什么在HttpContext null这里?
我已经看到这个问题已经针对 JavaScript 和其他语言多次回答了。在那里,它总是归结为获取快照并使用称为exists()检查的方法。但是在 Dart/Flutter 中,没有这样的方法。这是我现在所拥有的:
devicesRef.child(deviceId).once().then((DataSnapshot data) {
print(data.key);
print(data.value);
});
Run Code Online (Sandbox Code Playgroud)
我想检查一个名为的节点是否deviceId已经存在。
那么如何使用 Dart/Flutter 检查 Firebase 实时数据库中是否存在节点?
我有一个带有自定义/自定义样式按钮的用户控件.到目前为止,我使用Tap事件来调用click操作.但是,Tap似乎"太慢了".因此,当我连续两次单击按钮太快时,只有第一次点击才会触发事件.当我在屏幕上有两个按钮并且我连续点击它们时,会发生同样的情况.我想这与Tap事件有关(似乎只有当我的手指从屏幕上抬起时才会触发).
<ui:JapanButton x:Name="JapanButton1" Text="Japan" Tap="JapanButton1_OnTap"/>
Run Code Online (Sandbox Code Playgroud)
这就是为什么我想在用户控件中公开按钮的Click事件但不知道如何做到这一点.
<ui:JapanButton x:Name="JapanButton1" Text="Japan" Click="JapanButton1_OnClick"/>
Run Code Online (Sandbox Code Playgroud)
这是我目前拥有的:
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:telerikPrimitives="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Primitives"
x:Class="UI.JapanButton"
mc:Ignorable="d"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
d:DesignHeight="100" d:DesignWidth="480">
<UserControl.Resources>
<telerikPrimitives:NegativeConverter x:Key="NegativeConverter"/>
<Style x:Key="JapanButtoStyle" TargetType="Button">
<Setter Property="Background" Value="OrangeRed"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="FontSize" Value="40"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
<Grid Margin="{TemplateBinding Margin}">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal"/>
<VisualState x:Name="Pressed">
<Storyboard>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Foreground" Storyboard.TargetName="ContentContainer">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneBackgroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="Background" Storyboard.TargetName="ButtonBackground">
<DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PhoneForegroundBrush}"/>
</ObjectAnimationUsingKeyFrames>
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="BorderBrush" Storyboard.TargetName="ButtonBackground"> …Run Code Online (Sandbox Code Playgroud) 我创建了一个简单的 Slack App 应用程序,其唯一目的是将消息发送到频道。据我所知,有一个conversations.listAPI 可以列出所有公共频道以获得正确的 ID。
但是,作为第一步,我只想将消息发送到应用程序通道本身。如果我使用 D...ID,它会按预期工作。无需渠道邀请。但是我如何获得这个ID呢?conversations.list只返回公共频道,但不返回应用程序频道本身。
从以下(简化)接口开始,考虑到async/await,我想通过使用LiteDB数据库来实现它.
public interface IDataService
{
Task<User> GetUserAsync(int key);
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,LiteDB目前不支持异步方法.所有方法都是同步的.
我尝试了以下内容,但后来遇到了一些问题(进程并没有真正等待任何原因).接下来,我读到你应该只Task.Run()用于CPU绑定算法,因此不能用于数据库访问.
public Task<User> GetUserAsync(int key)
{
var task = Task.Run(() =>
{
return _users
.Find(x => x.Key == key)
.SingleOrDefault();
});
return task;
}
Run Code Online (Sandbox Code Playgroud)
即使我阅读了几篇博客文章和SO问题,我仍然不清楚如何为基于同步IO的代码制作一个正确编写的等待方法.
那么我该如何编写一个正确的等待方法呢?
注意:我无法更改界面.这是给出的.
c# ×7
sqlite ×3
async-await ×2
sqlite-net ×2
asp.net-core ×1
dart ×1
flutter ×1
httpcontext ×1
litedb ×1
mvvm-light ×1
razor ×1
slack-api ×1
swift ×1
uwp ×1
xaml ×1