如何检查WinRT应用程序是否在模拟器内运行?
对于Windows Phone,我使用以下代码:
Boolean isOnEmulator
= (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator);
Run Code Online (Sandbox Code Playgroud)
但我无法找到WinRT的解决方案.
这是我的场景 - 我有一个Windows商店应用程序.我有一个本地文件,以及一个指向互联网上文件的链接.有没有办法可以检查这两个文件是否相同,没有从链接下载文件?
用于获取文件的代码是:
private static async void SetImage(PlaylistItem song, string source, string imageName)
{
HttpClient client = new HttpClient();
HttpResponseMessage message = await client.GetAsync(source);
StorageFolder myfolder = Windows.Storage.ApplicationData.Current.LocalFolder;
StorageFile sampleFile = await myfolder.CreateFileAsync(imageName, CreationCollisionOption.ReplaceExisting);
byte[] byteArrayFile = await message.Content.ReadAsByteArrayAsync();
await FileIO.WriteBytesAsync(sampleFile, byteArrayFile);
song.Image = new BitmapImage(new Uri(sampleFile.Path));
}
Run Code Online (Sandbox Code Playgroud) 我有一个表(mytable)包含:
id, date
Run Code Online (Sandbox Code Playgroud)
和一些行(Id用于示例):
4235 null
3563 2013-11-27 08:02:53.917
3143 2013-11-27 01:04:51.917
1455 null
5223 2013-11-26 08:02:53.917
2123 2013-11-25 08:02:53.917
Run Code Online (Sandbox Code Playgroud)
我想选择今天之前的日期或日期为空的所有行.
所以在我的例子中,如果我运行查询2013-11-27我想得到:
4235 null
1455 null
5223 2013-11-26 08:02:53.917
2123 2013-11-25 08:02:53.917
Run Code Online (Sandbox Code Playgroud)
我想这样做:
select case when
(
(select DATEPART(yyyy,dailybudgetexceeded) from sensplit_commercial_goal where
commercialGoalId = 'dbe20d71-e304-4989-8524-5feef61d32a7') >= YEAR(GETDATE())
or...
Run Code Online (Sandbox Code Playgroud)
但也许有一个更短的方式.
任何帮助赞赏!
我最近遇到了要考虑在下一版本的C#中添加的功能列表。其中之一称为“默认接口方法”:
https://github.com/dotnet/csharplang/blob/master/proposals/default-interface-methods.md
简而言之,它将允许您在接口本身上定义实际的方法实现,这意味着接口现在可以具有实现。既然是这种情况,并且C#类可以从多个接口实现/继承,那么为什么我在世界上总是使用抽象类?
我唯一想到的是接口不能具有构造函数,因此可能需要在抽象类构造函数中运行一些逻辑,这将有理由定义一个抽象类。
还有其他人能想到的方案吗?
我正在使用 Microsoft.AspNetCore.SignalR 2.1 v1.0.4,并且使用 v1.0.4 的打字稿客户端使用 ChannelReader 流。
频道显示特定于单个实体的事件数据,因此当客户端的用户导航到该单个实体的页面呈现数据时,预计客户端将订阅频道。如果用户导航到同一页面但针对不同的实体,则客户端将进行另一个订阅调用。
现在我的问题是关于如何最好地取消订阅流,以及一般来说,流的生命周期对于集线器连接停止/启动场景下的客户端来说是什么,以及服务器是否显式中止连接(由于 access_token 超时从而触发客户端刷新他们的连接)?
似乎没有从 api 中浮现出一些连接状态,所以我目前使用 RxJs Subject 将一些连接状态呈现给我的 UI 组件/服务,即当集线器连接的启动调用成功时,我浮现“真”,当onclose 回调称为 I 表面“假”。这允许我尝试在先前订阅的流上调用 dispose 以在连接断开/停止期间清理内容,然后在成功启动调用时再次调用订阅流。
我试过在一个流上调用 dispose 如果集线器已连接,这很好,但如果连接处于断开状态,它会出错。我想知道这是否是一个错误。即使集线器断开连接,我也应该能够处理流吗?
可以只做一个delete streamsubscription然后根据需要重新创建,还是会以任何方式泄漏?
我有一些 C# 代码用于执行对象的深层复制:
public static T Copy<T>(T objectToCopy)
{
T result = default(T);
using (var memoryStream = new MemoryStream())
{
var formatter = new BinaryFormatter();
formatter.Serialize(memoryStream, objectToCopy);
memoryStream.Seek(0, SeekOrigin.Begin);
result = (T)formatter.Deserialize(memoryStream);
memoryStream.Close();
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
我从 Visual Studio 收到此警告:
警告 SYSLIB0011
'BinaryFormatter.Serialize(Stream)' 已过时:'BinaryFormatter 序列化已过时,不应使用。有关更多信息,请参阅https://aka.ms/binaryformatter。
我收到同样的警告BinaryFormatter.Deserialize(Stream)。
我查看了建议的链接,他们列出了一些首选的替代方案:
XmlSerializer并将DataContractSerializer对象图序列化为 XML 和从 XML 序列化。不要DataContractSerializer与NetDataContractSerializer.BinaryReader以及BinaryWriterXML 和 JSON。System.Text.Json对象图序列化为 JSON的API。我只是在努力弄清楚在我的具体情况下我将如何实施这些替代方案之一。
如果有人能在这方面帮助我,我将不胜感激。
谢谢你。
我在 Visual Studio 2019 中有一个 .Net 6.0 应用程序。我正在尝试让默认接口实现正常工作。由于某种原因,它似乎无法识别类定义中的默认实现。
这是一个示例代码片段:
public interface IFooBar
{
protected bool BoolProperty { get; set; }
protected Guid StringProperty { get; set; }
protected void SampleMethod1(string param)
{
}
protected void SampleMethod2()
{
}
}
public class FooBase
{
}
public class Foo : FooBase, IFooBar
{
protected bool IFooBar.BoolProperty { get; set; }
protected Guid IFooBar.StringProperty { get; set; }
protected SomeMethod()
{
SampleMethod1("Test String");
}
}
Run Code Online (Sandbox Code Playgroud)
以下是我的 Visual Studio 2019 项目文件的片段:
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework> …Run Code Online (Sandbox Code Playgroud) 我正在使用 .NET 8,DbContext在主构造函数中调用时,我的值为 null,但在普通构造函数中调用时,我的值为 null。
这是我的DbContext:
public class DataContext(DbContextOptions<DataContext> options) : DbContext(options)
{
public DbSet<Student> Students { get; set; }
public DbSet<Subject> Subjects { get; set; }
public DbSet<Teacher> Teachers { get; set; }
public DbTSet<Lesson> Lessons { get; set; }
public DbSet<Attendance> Attendances { get; set; }
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.AddInboxStateEntity();
builder.AddOutboxMessageEntity();
builder.AddOutboxStateEntity();
builder.Ignore<BaseEntity>();
}
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = new())
{
foreach (var entity in ChangeTracker
.Entries()
.Where(x => …Run Code Online (Sandbox Code Playgroud) 为什么C#的按位运算NOT符返回(the_number*-1)-1?
byte a = 1;
Console.WriteLine(~a); //equals -2
byte b = 9;
Console.WriteLine(~b); //equals -10
// Shouldn't a=0 and b=6?
Run Code Online (Sandbox Code Playgroud)
我怎么用C#做这个?
9 = 0b1001 -> NOT
= 0b0110 = 6
Run Code Online (Sandbox Code Playgroud) c# ×7
.net-core ×2
.net-8.0 ×1
asp.net-core ×1
bit ×1
c#-8.0 ×1
file ×1
http-headers ×1
masstransit ×1
mobile ×1
sql-server ×1
windows-8 ×1
youtube-api ×1