我是这个网站的新手,我不知道我是否提供了足够的信息 - 我会尽力=)
如果您使用 Notepad++,那么您就会知道我在说什么 - 当用户将 a 加载.exe到 Notepad++ 中时,NUL/\x0字符会被替换为NULL,它具有黑色背景和白色文本。我尝试将其粘贴到 Visual Studio 中,希望获得相同的输出,但它只是粘贴了一些空格...
有谁知道这是否是某个组合键或其他什么?我想用该NULL字符替换\x0,就像 Notepad++ =)
我知道我们可以声明一个命名元组,如:
var name = (first:"Sponge", last:"Bob");
Run Code Online (Sandbox Code Playgroud)
但是,我无法弄清楚如何将命名元组与泛型类型(例如 Dictionary )结合起来。
我尝试了以下变体,但没有运气:
Dictionary<string, (string, string)> name = new Dictionary<string, (string, string)>();
// this assignment yields this message:
// The tuple element name 'value' is ignored because a different name or no name is specified by the
// target type '(string, string)'.
// The tuple element name 'limitType' is ignored because a different name or no name is specified
// by the target type '(string, string)'.
name["cast"] = (value:"Sponge", limitType:"Bob");
// …Run Code Online (Sandbox Code Playgroud) 我在WPF应用程序中使用了额外的网格来设计各个响应组件。我有一个如下的视图:
<UserControl x:Class="..."
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:..."
mc:Ignorable="d"
xmlns:ge="clr-namespace:SourceChord.GridExtra;assembly=GridExtra.Wpf">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="...">
</ResourceDictionary>
<ResourceDictionary Source="...">
</ResourceDictionary>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</UserControl.Resources>
<UserControl.Width>
<StaticResource ResourceKey="ApplicationWidth" />
</UserControl.Width>
<Grid Style="{StaticResource SelectContainer}"
ge:GridEx.RowDefinition="1*, 3*"
ge:GridEx.TemplateArea="Message/ Companies/">
<Grid ge:GridEx.AreaName="Message"
ge:GridEx.RowDefinition="*"
ge:GridEx.ColumnDefinition="*,*"
ge:GridEx.TemplateArea="L1 L2/"
>
<TextBlock Text="{Binding Path=MessageL1Text}" Style="{StaticResource MessageTextStyle}" ge:GridEx.AreaName="L1"/>
<TextBlock Text="{Binding Path=MessageL2Text}" Style="{StaticResource MessageTextUrduStyle}" ge:GridEx.AreaName="L2"/>
</Grid>
<Grid ge:GridEx.AreaName="Companies"
ge:GridEx.RowDefinition="*"
ge:GridEx.ColumnDefinition="1*,1.5*,1.5*,1.5*,1.5*,1.5*,1.5*,1*"
ge:GridEx.TemplateArea="MarginLeft Company1 Company2 Company3 Company4 Company5 More MarginRight/">
<Grid ge:GridEx.AreaName="MarginLeft"></Grid>
<Grid ge:GridEx.AreaName="MarginRight"></Grid>
<Grid ge:GridEx.AreaName="Company1" Style="{StaticResource CompanyButtonOneStyle}">
<Grid.Resources>
<ImageBrush x:Key="AddButtonImageBrush" ImageSource="{Binding …Run Code Online (Sandbox Code Playgroud) 大家好,
有人可以解释一下Factory方法设计模式和Bridge模式之间的区别吗?
因为据我所知,这两种设计模式都用于分隔接口和实现:
将抽象与实现分离。抽象将客户端代码与实现分开。因此,可以在不影响客户端代码的情况下更改实现,并且在实现更改时无需编译客户端代码。
工厂方法:
没有工厂方法的问题:
在某些情况下,我们有一个包含一些类的库来实现客户端业务逻辑。在客户端应用程序中,我们创建库类的对象以完成任务。
但是有时,根据客户要求合并其他功能,我们可能需要在库中添加其他类。然后,我们需要在客户端应用程序中创建新类的对象。
因此,每次在库端进行新更改时,客户端都需要在其末端进行一些相应的更改并重新编译代码。
使用工厂方法:
为避免此问题,我们使用Factory方法将对象创建与客户端应用程序分离。客户只需要调用库的工厂方法,而不必担心对象创建的实际实现。
因此,我们创建Factory方法来创建对象并将其移动到单独的实现文件中。现在,实现文件是唯一需要了解派生类的文件。因此,如果对任何派生类进行了更改或添加了任何新类,则实现文件是唯一需要重新编译的文件。使用工厂的每个人都只会关心该接口,该接口在应用程序的整个生命周期中都应保持一致。
客户端应用程序交互->工厂方法和调用->实现
如果我采用以下示例程序,则在添加任何类或对该类进行任何更改之后,仅重新编译Vehicle.cpp文件就足够了吗?而且在创建工厂方法时,我们是否使用静态方法?
车辆
#include <iostream>
using namespace std;
enum VehicleType {
VT_TwoWheeler, VT_ThreeWheeler, VT_FourWheeler
};
// Library classes
class Vehicle {
public:
virtual void printVehicle() = 0;
static Vehicle* Create(VehicleType type);
};
class TwoWheeler : public Vehicle {
public:
void printVehicle() {
cout << "I am two wheeler" << endl;
}
};
class ThreeWheeler : public Vehicle {
public:
void printVehicle() {
cout << "I am three wheeler" …Run Code Online (Sandbox Code Playgroud) 我想使用引用本地存储库的提交哈希来提供 Docker 构建命令的上下文。
涵盖 Docker 构建的文档指定如何引用远程存储库上而不是本地存储库上的分支或标签。参考
我尝试用协议替换 URLfile://以引用本地 git 存储库,但这会返回错误
docker build file:///home/username/repositories/hello-world
错误
无法准备上下文:找不到路径“file:///home/username/repositories/hello-world”
我想将本地 Git 存储库(特定提交、标签或分支)作为 Docker 构建映像的构建上下文。
我已经看过这个问题Docker build Specific local gitbranch但我不希望必须克隆或签出分支来从中构建。
我正在尝试Microsoft.Toolkit.Wpf.UI.Controls.WebView在wpf桌面应用程序中使用控件。它似乎比Web浏览器控件使用的资源少得多,并且基于边缘而更新得多。但是,与webbrowser控件不同,除非选中,否则它将不会滚动。即,当鼠标悬停在Web浏览器上时,无需先选择就可以上下滚动,但是如果Webview不是当前选定的控件,则Webview将忽略鼠标滚轮。
使用VS2019,以下代码演示了该问题。
<Window x:Class="test0.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:WPF="clr-namespace:Microsoft.Toolkit.Wpf.UI.Controls;assembly=Microsoft.Toolkit.Wpf.UI.Controls.WebView"
Title="MainWindow" Height="600" Width="1024">
<Grid>
<StackPanel>
<Button Content="hello world" Height="100" />
<WPF:WebView Source="https://bing.com" Height="250" />
<WebBrowser Source="https://bing.com" Height="250" />
</StackPanel>
</Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)
在运行时,当鼠标指针悬停时,两个浏览器控件都将滚动。单击按钮(从两个浏览器中移出焦点)后,只有Web浏览器控件在鼠标悬停时滚动。
是否有解决此问题的解决方法?
使用:.NET Framework 4.7.2和Microsoft.Toolkit.Wpf.UI.Controls.WebView 5.1.1
我有一个Xamarin.Forms应用程序,其中使用 Autofac 进行 DI。
所以我想要的很简单,但我无法做一些看起来很容易做的事情。
所以我有一个类,它有两个构造函数,它们都有一个参数,并且根据某些条件我想解析其中一个。举个例子,我有一个类 A,我想要的是基于条件 B 或 C 应该得到解决。
例如:
public class A
{
public A(B bObject)
{...}
public A(C cObject)
{...}
}
Run Code Online (Sandbox Code Playgroud)
但我无法理解如何做到这一点。我尝试做如下的事情:
登记:
builder.RegisterType<A>().
UsingConstructor(typeof(C)).
Named<A>(nameof(C));
builder.RegisterType<A>().
UsingConstructor(typeof(B)).
Named<A>(nameof(B));
Run Code Online (Sandbox Code Playgroud)
解决:
DiContainer.ResolveNamed<A>(nameof(B));
DiContainer.ResolveNamed<A>(nameof(C));
Run Code Online (Sandbox Code Playgroud)
注:我已经在容器中注册了B和C,如下图:
builder.RegisterType<B>();
builder.RegisterType<C>()
Run Code Online (Sandbox Code Playgroud)
我对 AutoFac 有点陌生,我什至不确定这是否是正确的方法,我认为这与我注册两次有关,我不确定。
强烈感谢任何建议或帮助。
我有这个 Json:
{
"UpdatePack":"updatePacks\/1585654836.pack",
"Updates":[
{
"Name":"MsgBoxEx",
"version":"1.5.14.88",
"ChangeLog":"BugFix: Form didn't resize correct.",
"Hash":"5FB23ED83693A6D3147A0485CD13288315F77D3D37AAC0697E70B8F8C9AA0BB8"
},
{
"Name":"Utilities",
"version":"2.5.1.58",
"ChangeLog":"StringManagement updated.",
"Hash":"05E6B3F521225C604662916F50A701E9783E13776DE4FCA27BE4B69705491AC5"
}
]
}
Run Code Online (Sandbox Code Playgroud)
我创建了 2 个用于反序列化它的类。
class UpdatesList
{
public string Name { get; set; }
public string Version { get; set; }
public string ChangeLog { get; set; }
public string Hash { get; set; }
}
class JsonObjectHolder
{
public string UpdatePack { get; set; }
//public Dictionary<int, MyData> { get; set; }
public Dictionary<int, UpdatesList> Updates …Run Code Online (Sandbox Code Playgroud) 这个非常简单的例子:
int numLanes = 8;
var tasks = new List<Task>();
for (var i = 0; i < numLanes; ++i)
{
var t = new Task(() =>
{
Console.WriteLine($"Lane {i}");
});
tasks.Add(t);
}
tasks.ForEach((t) => t.Start());
Task.WaitAll(tasks.ToArray());
Run Code Online (Sandbox Code Playgroud)
产生:
Lane 8
Lane 8
Lane 8
Lane 8
Lane 8
Lane 8
Lane 8
Lane 8
Run Code Online (Sandbox Code Playgroud)
这与预期不同,参数i未正确传递。我曾想过用来Action<int>包装代码,但看不到我会怎么做。我不想写一个专门的方法,就像Task CreateTask(int i)我对如何使用 lambda 感兴趣一样。
执行此操作的正常方法是什么 - 使用不同的参数值并行地多次启动相同的代码?
我尝试使用元组指定 nUnit 测试用例,但在 VisualStudio 中收到编译器错误。
这个简单的例子演示了我正在尝试做的事情:
[TestCase((1, 2), (3, 5))]
public void TestRangeOverlaps((int start, int end) firstRange, (int start, int end) secondRange)
{
}
Run Code Online (Sandbox Code Playgroud)
如果这是可能的,我错过了什么?