我刚刚在反射器中浏览文件,并在结构构造函数中看到了这个:
this = new Binder.SyntaxNodeOrToken();
Run Code Online (Sandbox Code Playgroud)
我以前没见过那个术语.有人可以解释这个赋值在C#中意味着什么.谷歌很难.
在 C# 中,是否有一种方法可以with在不知道对象的类型(或基类型)的情况下在接口上使用关键字?
我正在想象类似DoSomething以下伪代码中的方法(这不是有效的 c#)。该代码DoSomething预计会对所有实现ISomeRecord.
该DoSomething2方法可以编译,但仅适用于类型的记录SomeRecord,不适用于SomeRecord.
public interface ISomeRecord
{
bool SomeProp { get; }
}
public record SomeRecord : ISomeRecord
{
public bool SomeProp { get; init; }
}
public class SomeUtil
{
public ISomeRecord DoSomething(ISomeRecord rec)
{
return ( rec as record ) with { SomeProp = false };
}
public ISomeRecord DoSomething2(ISomeRecord rec)
{
return ( rec as SomeRecord ) with { SomeProp …Run Code Online (Sandbox Code Playgroud) 我对Windows中的文本到语音技术感到困惑.我有一个稍微特殊的要求:我需要使用System.Speech程序集从Win 7中运行的.net程序输出语音.我想要一个好的,机器人的声音,没有像微软安娜那样强烈的美国口音.
哪个第三方声音适用于.net api?有谁知道一个好的英国(但不是太英国)的声音,最好免费或便宜?
是否可以自定义代码折叠在Visual Studio代码中的工作方式?
我使用了一种在各种不同文档类型中定义代码区域的通用模式.
因此,对于XML,我用<!-- #region -->和包装文本的部分<!-- #endregion -->
对于c#,我#region用来#endregion,
对于TypeScript/Javascript,我使用/* #region */和/* #endregion */.
在完整的Visual Studio(不是VS代码)中,我有一个自定义扩展,可以跨文档类型窥探模式,并根据它创建折叠,允许我创建整洁的自定义文档轮廓.我想在Visual Studio Code中使用相同的模式.是否可以创建一个自定义VS代码扩展来检测这些注释模式,并以某种方式根据模式标记折叠?
我正在使用.net核心与IdentityServer 4.我有一个Web api,以及一个访问api上安全端点的MVC应用程序.它在设置上与IdentityServer快速入门非常相似:
https://github.com/IdentityServer/IdentityServer4.Samples/tree/release/Quickstarts/6_AspNetIdentity
我发现我access_tokens即将到期,我想了解如何重新谈判refresh_tokens.
以下面的代码为例(摘自此处的快速入门):
public async Task<IActionResult> CallApiUsingUserAccessToken()
{
var accessToken = await HttpContext.Authentication.GetTokenAsync("access_token");
var client = new HttpClient();
client.SetBearerToken(accessToken);
var content = await client.GetStringAsync("http://localhost:5001/identity");
ViewBag.Json = JArray.Parse(content).ToString();
return View("json");
}
Run Code Online (Sandbox Code Playgroud)
如果access_token已过期,则会因401响应而失败.是否有内置机制重新协商access_token使用refresh_token?
我试图通过WebSockets让Bing Speech API在C#中工作.我已经通过实施在Javascript看着这里,并已按照规程说明在这里,但我已经遇到了一个完整的砖墙.我不能使用现有的C#服务,因为我在Linux容器中运行,所以我需要在.net Core上使用一个实现.令人讨厌的是,现有的服务是封闭源的!
我可以成功连接到Web套接字,但我无法让服务器响应我的连接.我期待turn.start从服务器收到一条短信,但是一旦我发送了几个字节的音频文件,我就会从服务器上启动.我知道这个音频文件是在正确的格式,因为我已经从C#的服务样本直接得到它在这里.
我觉得我已经筋疲力尽了.我现在唯一能想到的是我没有正确发送音频块.目前,我只是连续发送4096字节的音频文件.我知道第一个音频消息包含RIFF标题,只有36个字节,然后我只是发送它与下一个(4096-36)字节.
这是我的完整代码.您应该只能将其作为.net核心或.net框架控制台应用程序运行,并且需要一个音频文件和一个API密钥.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Net.WebSockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
Task.Run(async () =>
{
var bingService = new BingSpeechToTextService();
var audioFilePath = @"FILEPATH GOES HERE";
var authenticationKey = @"BING AUTHENTICATION KEY GOES HERE";
await bingService.RegisterJob(audioFilePath, authenticationKey);
}).Wait();
}
}
public class BingSpeechToTextService
{
/* …Run Code Online (Sandbox Code Playgroud) 假设我有一个在应用程序持续时间内存在的对象.我们称之为GlobalWorker.GlobalWorker具有其他对象可以订阅的事件,例如UserLoggedIn.现在想象一下,我有一个Silverlight页面或一个asp.net页面,它在构造时订阅了UserLoggedIn事件.
public SomePage()
{
GlobalWorker.Instance.UserLoggedIn += new EventHandler(OnUserLoggedIn);
}
private void OnLoggedIn(object sender, EventArgs e)
{
}
Run Code Online (Sandbox Code Playgroud)
是否存在此事件会阻止页面被垃圾回收?如果是这样,在这个实例中使用的最佳模式是什么:弱事件处理程序,将订阅移动到Load事件并取消订阅UnLoad事件?
我刚刚一直在调查与蚂蚁内存分析器一些Silverlight控件(辉煌!),结果发现我的一些控件在内存中保持周围.这个问题的解决已经在控制"卸载",并清除我在代码完成的任何绑定模板和内容值重置为null.
这是处理Silverlight自定义控件的正常模式吗?我过去没有做到这一点吗?
有没有人知道一个范例,比如用整洁的清理来编写Silverlight控件的模式?
附录我一直在进一步调查这一点,发现当DataContext设置为null时,将删除对DataContext的绑定.似乎正确的过程是在Loaded事件中设置任何Datacontext值,并在Unloaded事件中将其设置为null.我编写Silverlight Templated控件的范例仍然存在根本问题,因为我无法强制销毁ContentControls(请参阅我的问题:为什么Silverlight ContentControls不会被垃圾收集?).
我刚刚在 Blazor WebAssembly 中完成了第一个重要的测试应用程序。Blazor 是令人印象深刻的东西,但我发现很难推理属性的更改如何导致 DOM 更新 - 例如,在 Razor 组件中引用该属性。
<div>@SomeProperty</div>
Run Code Online (Sandbox Code Playgroud)
public int SomeProperty {get;set;}
Run Code Online (Sandbox Code Playgroud)
在 WPF 中,很容易推断更改如何流动并导致呈现更改,因为它们是由事件和 DependencyProperty 更改触发的。您可以看到这些并绑定到它们。在 Blazor 中,您可以通过某种方式更改属性值并更新页面。这背后的精确机制有点像魔术。因此,很难推断如何删除复杂组件的不必要更新。
谁能解释一下这个主题的基础?
是否有任何文档或视频深入探讨 Blazor 的这一领域?
我一直在调查为什么我的一些控件没有被垃圾收集,并注意到很容易阻止从ContentControl继承的简单控件被破坏.这是一个例子:
这是我的自定义ContentControl:
public class MyCustomControl : ContentControl
{
public MyCustomControl()
{
Debug.WriteLine("Constructed");
}
~MyCustomControl()
{
Debug.WriteLine("Destroyed");
}
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我把它放在这样的页面上:
<navigation:Page x:Class="SimpleTestBed.Views.CustomControl"
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"
mc:Ignorable="d"
xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
xmlns:local="clr-namespace:SimpleTestBed"
d:DesignWidth="640" d:DesignHeight="480"
Title="CustomControl Page">
<Grid x:Name="LayoutRoot">
<StackPanel>
<local:MyCustomControl>
<TextBox Text="{Binding SomeProperty,Mode=TwoWay}"></TextBox>
</local:MyCustomControl>
</StackPanel>
</Grid>
Run Code Online (Sandbox Code Playgroud)
使用以下代码:
public partial class CustomControl : Page
{
public CustomControl()
{
InitializeComponent();
this.DataContext = new CustomControlViewModel();
this.Unloaded += new RoutedEventHandler(OnUnloaded);
}
void OnUnloaded(object sender, RoutedEventArgs e)
{
this.DataContext = null;
}
// Executes when the user navigates to …Run Code Online (Sandbox Code Playgroud) c# ×5
silverlight ×2
.net ×1
bing-speech ×1
blazor ×1
c#-9.0 ×1
interface ×1
lifecycle ×1
sapi ×1
struct ×1