是否有办法阻止Visual Studio在按下时启动调试器F11?我想经常按下时经常会误按它F12.我不想放弃Step-into的功能,F11但它在启动应用程序时很烦人.
标题是自我解释的.我想在工具栏中添加一个按钮,以便运行外部可执行文件.
我怎样才能做到这一点?
在我当前的项目(.NET Windows Forms应用程序)中,我要求.NET窗体表单应该本地化,但是本地化元素(只是翻译,而不是图像或控件位置)应该来自数据库,以便启用最终用户可以根据需要修改控件可本地化属性(只是标题/文本).为了让开发人员不受本地化问题的影响,对我来说最好的解决方案就是在VS设计器中将表单标记为Localizable.这将把所有可本地化的属性值放在表单.resx文件中.
现在我的问题是如何从数据库提供翻译.在表单被标记为Localizable的那一刻,VS Forms设计器将放置可以本地化的所有内容都是表单.resx文件.设计人员还将修改标准的designer.cs InitializeComponent方法,以便它实例化ComponentResourceManager,然后使用该资源管理器加载对象(控件和组件)的可本地化属性.
我已经看到了一些解决方案,人们已经建立了自己的方法,将本地化属性应用于Form及其控件.我见过的所有解决方案通常归结为递归迭代Form的Controls集合及其控件并应用翻译.不幸的是,.NET Forms本地化并不是那么简单,并不能涵盖所有场景,特别是如果你有一些第三方控件.例如:
this.navBarControl.OptionsNavPane.ExpandedWidth = ((int)(resources.GetObject("resource.ExpandedWidth")));
//
// radioGroup1
//
resources.ApplyResources(this.radioGroup1, "radioGroup1");
...
this.radioGroup1.Properties.Items.AddRange(new DevExpress.XtraEditors.Controls.RadioGroupItem[] {
new DevExpress.XtraEditors.Controls.RadioGroupItem(resources.GetString("radioGroup1.Properties.Items"), resources.GetString("radioGroup1.Properties.Items1")),
new DevExpress.XtraEditors.Controls.RadioGroupItem(resources.GetString("radioGroup1.Properties.Items2"), resources.GetString("radioGroup1.Properties.Items3"))});
Run Code Online (Sandbox Code Playgroud)
我见过的所有解决方案都无法进行上述组件所需的翻译.
由于VS已经生成了在需要的地方提供翻译的代码,我理想的解决方案是以某种方式用我自己的派生类替换ComponentResourceManager.如果我可以在InitializeComponent中替换以下行:
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
Run Code Online (Sandbox Code Playgroud)
同
System.ComponentModel.ComponentResourceManager resources = new MyComponentResourceManager(typeof(Form1));
Run Code Online (Sandbox Code Playgroud)
然后我可以毫无问题地解决其他问题.
不幸的是我没有找到我怎么能做那样的事情所以我在这里问一个关于如何做到这一点的问题.
PS我还接受符合要求的任何其他本地化解决方案:1.无需重新部署应用程序即可更改翻译2.开发人员在创建表单/用户控件时不应注意翻译
谢谢.
编辑:拉里提供了一本很好的参考书,其中的代码部分解决了我的问题.有了这个帮助,我能够创建自己的组件,替换InitializeComponent方法中的默认ComponentResourceManager.下面是一个名为Localizer的组件的代码,它使用自定义MyResourceManager替换ComponentResourceManager,以便其他人也可以从中受益:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.CodeDom;
using System.ComponentModel.Design;
namespace LocalizationTest
{
[Designer(typeof(LocalizerDesigner))]
[DesignerSerializer(typeof(LocalizerSerializer), typeof(CodeDomSerializer))]
public class Localizer : Component
{
public static void GetResourceManager(Type type, out ComponentResourceManager …Run Code Online (Sandbox Code Playgroud) .net localization resourcemanager visual-studio-2010 winforms
我喜欢在 React 中你可以在主组件文件中快速创建小组件。Vue 3 组合 API 可以实现类似的功能吗?
像这样的东西:
组件.vue
<script setup>
const SmallComponent = <div>Test</div>
</script>
<template>
<SmallComponent/>
</template>
Run Code Online (Sandbox Code Playgroud) 我有一个应用程序,当我单击一个按钮时,它会加载一个TabItem带有UserControl. 这工作正常,但是......当我再次单击添加按钮时,另一个TabItem添加了UserControl. 问题来了。当我在 tab1 中添加一些数据并切换到 tab2 时,我也会在那里看到输入的数据。这怎么可能?我ViewModel对每个都使用了一个新的,UserControl因此 tab1 和 tab2 上的两个用户控件如何显示相同的数据。它可能会很愚蠢,但我找不到它......
结构是这样的:MainWindow加载一个UserControl只有 a 的 a TabControl。单击菜单中的“添加”按钮后,将添加一个带有新TabItem内容的新UserControl内容。
这里有一些看起来像这样但不同的问题。
这是一些代码。
TabControl.xaml:
<Grid>
<TabControl x:Name="tabControl" ItemsSource="{Binding TabItems}" SelectedIndex="0">
<TabControl.Resources>
<DataTemplate DataType="{x:Type ViewModel:OverviewViewModel}">
<my:OverviewControl />
</DataTemplate>
<DataTemplate DataType="{x:Type ViewModel:MemberViewModel}">
<my:MemberControl />
</DataTemplate>
</TabControl.Resources>
<TabControl.ItemContainerStyle>
<Style TargetType="TabItem">
<Setter Property="Header" Value="{Binding Header}" />
</Style>
</TabControl.ItemContainerStyle>
</TabControl>
</Grid>
Run Code Online (Sandbox Code Playgroud)
TabControl.cs:
public TabControl()
{
InitializeComponent();
this.DataContext …Run Code Online (Sandbox Code Playgroud) VB.Net没有等效的C#volatile关键字,因此您必须手动实现volatile,这通常通过在读取之前和写入之后调用Thread.MemoryBarrier()来完成.所以这样的东西等同于声明C#volatile变量:
''' <summary>
''' Gets a value indicating whether this instance is disposed.
''' </summary>
Public Property IsDisposed As Boolean
Get
Threading.Thread.MemoryBarrier()
Return _isDisposed
End Get
Private Set(value As Boolean)
_isDisposed = value
Threading.Thread.MemoryBarrier()
End Set
End Property
Run Code Online (Sandbox Code Playgroud)
如果我写入变量的唯一地方是通过setter并且在写入之后我总是调用Thread.MemoryBarrier(),那么在读取之前我想知道内存屏障.
我可以在读取之前安全地删除Thread.MemoryBarrier()吗?
编辑:为了使它更清楚,我问我是否可以在读取之前删除Thread.MemoryBarrier(),以便为每次读取删除内存栅栏的成本.
我今天在VB.NET中遇到了关于拳击和参考比较的行为,这是我没想到的.为了说明我编写了一个简单的程序,它试图以原子方式更新任何类型的变量.
这是C#中的一个程序(https://dotnetfiddle.net/VsMBrg):
using System;
public static class Program
{
private static object o3;
public static void Main()
{
Console.WriteLine("Hello World");
Test<DateTimeOffset?> value = new Test<DateTimeOffset?>();
Console.WriteLine(value.Value == null);
DateTimeOffset dt1 = new DateTimeOffset(2017, 1, 1, 1, 1, 1, TimeSpan.Zero);
DateTimeOffset dt2 = new DateTimeOffset(2017, 1, 2, 1, 1, 1, TimeSpan.Zero);
Console.WriteLine(value.TrySetValue(null, dt1));
Console.WriteLine(value.Value == dt1);
// this should fail
Console.WriteLine(value.TrySetValue(null, dt2));
Console.WriteLine(value.Value == dt1);
// this should succeed
Console.WriteLine(value.TrySetValue(dt1, dt2));
}
}
public class Test<T>
{
public T …Run Code Online (Sandbox Code Playgroud) 假设我有一个DateTime参考,我希望在前一天的15:00获得时间.如果我说
DateTime someTime = ....;
DateTime yesterday1500 = someTime.toDateMidnight().toDateTime().minusDays(1).plusHours(15);
Run Code Online (Sandbox Code Playgroud)
然后这将在所有日子工作,除非有夏令时变化.
如果someTime ='1.4.2014',我会得到'31 .3.2014 15:00'.
如果someTime = '31 .3.2014'我会得到'30 .3.2014 16:00'.
我能想到的最好的是
yesterday1500 = new DateTime(someTime.getYear(), someTime.getMonthOfYear(), someTime.getDayOfMonth(), 15, 0, 0, 0);
Run Code Online (Sandbox Code Playgroud)
它工作正常,但看起来很笨重.有没有更好的办法?
编辑:我在克罗地亚是CEST(UTC + 01:00)时区.
编辑2:添加了... toDateMidnight().toDateTime()...示例代码,表明someTime可以在任何时间点
我一直在阅读很多各种博客和StackOverflow问题,试图找到我的问题的答案,最后我找不到任何东西,所以我想自己问这个问题.
我正在构建一个应用程序,其中我有一个长时间运行的工作线程,它执行一些操作并在运行期间将一些结果放入变量中.工作线程一直在工作,并不断产生一些结果,我只对结果的"当前"值感兴趣.在某些时候,另一个线程将获得工作线程运行的"当前"结果并对其执行某些操作.
这样的工作线程的简单实现可以这样做:
Public Class Worker
Private _result As DateTimeOffset?
Public ReadOnly Property Result As DateTimeOffset?
Get
Return _result
End Get
End Property
Public Sub ThreadMethod()
' Do something
_result = x
' .
' .
_result = y
' .
' .
' etc
End Sub
End Class
Run Code Online (Sandbox Code Playgroud)
现在让我说我有一个想要消费结果的消费者:
Public Class Consumer
Private _worker As Worker
Public Sub Consume()
Dim result As DateTimeOffset?
While True
' Do some work on your own
' .
' .
' Get current …Run Code Online (Sandbox Code Playgroud) 我有一个 ASP.NET Core (3.1) 应用程序,它是自托管的并作为服务运行。我想为其公开一个 HTTPS 端点。在同一台计算机上安装了一个 IIS,其中已配置了 https 和证书:

我还可以通过 powershell 列出它:
> get-childitem cert:\LocalMachine\My\ | format-table NotAfter, Subject
NotAfter Subject
-------- -------
27.10.2023 07:38:45 <irrelevant>
08.03.2022 09:52:44 CN=a7642e58-2cdf-4e9b-a277-60fad84d7c64, DC=3336d6b0-b132-47ee-a49b-3ab470a5336e
23.02.2022 21:51:53 CN=a7642e58-2cdf-4e9b-a277-60fad84d7c64, DC=3336d6b0-b132-47ee-a49b-3ab470a5336e
27.10.2031 06:48:06 CN=a7642e58-2cdf-4e9b-a277-60fad84d7c64
26.10.2024 10:41:03 E=****.com, CN=****, OU=IT, O=****, L=****, S=***, C=**
Run Code Online (Sandbox Code Playgroud)
我更改了 appsettings.json 以使用商店中的证书:
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Warning"
}
},
"AllowedHosts": "*",
"Kestrel": {
"EndPoints": {
"Http": {
"Url": "http://*:5000"
},
"HttpsDefaultCert": {
"Url": "https://*:5001"
} …Run Code Online (Sandbox Code Playgroud) ssl ssl-certificate kestrel-http-server asp.net-core .net-core-3.1
.net ×4
vb.net ×3
asp.net-core ×2
c# ×2
.net-core ×1
boxing ×1
caching ×1
datetime ×1
http-caching ×1
java ×1
javascript ×1
jodatime ×1
jsx ×1
localization ×1
memory-model ×1
mvvm ×1
pgadmin-4 ×1
reference ×1
ssl ×1
time ×1
vue.js ×1
vuejs3 ×1
winforms ×1
wpf ×1
wpf-controls ×1