对于一个新项目,我想尝试新的 .net core 3.0 WPF 项目,我想将它与 MvvmLight 结合使用。但是,在 .net 核心中并与 Visual Studio Code 结合使用时,您不会获得任何脚手架或默认项目。然后还有一个谜团是如何让它工作......
我知道我需要在 app.xaml.cs、mainwindow.xaml 和 mainwindow.xaml.cs 中做一些事情。以及创建一些 ViewModelLocator 服务。但是 MvvmLight 的文档在这方面有点空洞。
我在 SO(MvvmLightLibsStd10 和 UWP)上发现了以下问题,但在我的情况下它并不完整,我也不确定我应该使用普通包还是特殊的 std10 版本。
2019 年 6 月 26 日更新, 我使用 MvvmLightLibsStd10 版本 5.4.1.1 使其与以下代码一起工作。
应用程序.xaml
<Application.Resources>
<ResourceDictionary>
<vm:ViewModelLocator x:Key="Locator" xmlns:vm="clr-namespace:$AssemblyName$.ViewModel" />
</ResourceDictionary>
</Application.Resources>
Run Code Online (Sandbox Code Playgroud)
主窗口.xaml
DataContext="{Binding ValidatorListViewModel, Source={StaticResource Locator}}">
Run Code Online (Sandbox Code Playgroud)
ViewModelLocator.cs
using GalaSoft.MvvmLight.Ioc;
namespace $AssemblyName$.ViewModel
{
public class ViewModelLocator
{
public ViewModelLocator()
{
SimpleIoc.Default.Register<ValidatorListViewModel>();
}
public ValidatorListViewModel ValidatorListViewModel => SimpleIoc.Default.GetInstance<ValidatorListViewModel>();
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 esp32 (slave) 和 rf24l01 模块做无线传感器节点。我的下一步是将我的奴隶置于睡眠模式(可能是深度睡眠)。我可以在我的项目中使用深度睡眠吗?
他们说
存储在该内存中的所有内容都被清除并且无法访问。
那么我所有的void setup()
代码都被消灭了吗?或者只是我的pack0.temp,潮湿的土壤被消灭了?
我的代码附在下面
struct package0
{
float temperature = 0;
float humidity = 0;
int soil = 0;
};
typedef struct package0 Package0;
Package0 pack0;
/**********************************/
/**************RF24****************/
RF24 radio(25,26);
RF24Network network(radio);
const uint16_t this_node = 01;
const uint16_t master00 = 00;
const unsigned long interval = 3000;
/**********************************/
void setup() {
dht.begin();
radio.begin();
network.begin(90, this_node);
radio.setPALevel(RF24_PA_MIN);
radio.setDataRate(RF24_250KBPS);
}
void loop() {
// put your main code here, to run repeatedly: …
Run Code Online (Sandbox Code Playgroud) 我有一个带有指针成员的类,例如:
class MyClass
{
public:
void setPointer(Pointer* ptr){_pointer = ptr;}
private:
Pointer* _pointer{nullptr};
};
Run Code Online (Sandbox Code Playgroud)
MyClass不拥有_pointer的内存。它只有一个指针来调用所需的方法。
我开始写书~MyClass()
,幸运的是我意识到它不应该删除,_pointer
因为它不拥有它。
显示MyClass没有该指针的所有权的最佳方法是什么?
编辑:
我应该在所有者类中使用unique_ptr,在MyClass中使用shared_ptr,还是它们都应使用shared_ptr?
IDE:Intellij
我使用 Lombok 的 NonNull 注释自动生成空指针检查并在方法参数和返回类型上引发异常。
在编写单元测试时,“null”方法参数确实会引发异常,但 null 返回类型不会引发异常。
import lombok.NonNull;
public @NonNull String function( @NonNull String input) {
return null;
}
Run Code Online (Sandbox Code Playgroud)
以下测试失败:
@Test
public void
whenReturnTypeIsNull_ThenIllegalArgumentExceptionIsThrown(){
assertThrows(IllegalArgumentException.class, ()-> testClass.function() );
}
Run Code Online (Sandbox Code Playgroud)
随着消息:
Expected java.lang.IllegalArgumentException to be thrown, but nothing was thrown
Run Code Online (Sandbox Code Playgroud) 这个问题是由于检查指针值nullptr
受到clang和gcc 的不均衡处理而引起的。因为this
它们都发出警告,但是对于address-of
在对象上使用运算符获取的指针,它们保持安静。
我很确定这样的指针应该一直有效,因为现代编译器从快乐的90年代实际上取消了对c ++代码的检查,导致了我们遇到的错误。
令我感到困惑的是,为什么编译器在一般情况下保持安静。是否可以通过某种方式if
触发,或者这仅仅是两个主要编译器中的设计决策?在开始编写补丁或调试编译器开发人员之前,我想确保我没有错过任何内容。
玩具示例:
#include <iostream>
class A {
void f(){
if(!this) {
std::cout << "This can't trigger, and compilers warn about it.";
}
}
};
void f(A& a){
A* ptr = &a;
if(ptr == nullptr) {
std::cout << "Can this trigger? Because gcc and clang are silent.";
}
}
Run Code Online (Sandbox Code Playgroud)
尽管这个问题看起来很愚蠢,但我发现它很实用。如果使用臭代码工作,则此优化将导致致命的结果,因此警告将是非常有用的诊断。
以补充情况。clang和gcc都知道检查具有不变的评估能力,因为即使对于干净的代码:
void g(A* a){
A* ptr = a;
if(ptr == nullptr) {
std::cout << "Gee, can …
Run Code Online (Sandbox Code Playgroud) 我能够部署 Azure Functions 以将 SignalR 消息传递到 Azure 门户,但local.settings.json
包含SignalRConnectionString
运行 SignalR 消息传递所需的文件未上传。如何在 Azure 门户上添加此字符串?
Azure 门户上的错误消息:
Microsoft.Azure.WebJobs.Extensions.SignalRService:必须通过“AzureSignalRConnectionString”应用设置、“AzureSignalRConnectionString”环境变量或直接在代码中通过 SignalROptions.ConnectionString 或 SignalRAttribute.ConnectionStringSetting 设置 SignalR 服务连接字符串。
我使用以下命令构建了一个 docker 容器:
FROM openjdk:8-jdk
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
openjfx \
unzip \
&& apt-get clean \
&& rm -f /var/lib/apt/lists/*_dists_*
Run Code Online (Sandbox Code Playgroud)
但我生成的 java 容器仍然没有 java fx.. 正如此例外所证明的:
...[org.neo4j.ogm.session.SessionFactory]: Factory method 'sessionFactory' threw exception; nested exception is java.lang.TypeNotPresentException: Type javafx.util.Pair not present
我也尝试过:
FROM openjdk:8-jdk
RUN apt-get update && apt-get install -y --no-install-recommends openjfx && rm -rf /var/lib/apt/lists/*
Run Code Online (Sandbox Code Playgroud)
这没有起作用。
有人有好的解决办法吗?
在C#中使用IActiveScriptParse32 :: ParseScriptText时,有人遇到过内存泄漏问题吗?我需要一个能够解析JavaScript代码的ScriptEngine。(除已使用的内存外,一切正常
问题是,传递的JavaScript代码越长,函数“ ParseScriptText”分配的非托管内存就越多。
我不知道如何释放分配的空间。我实际上在解析脚本后已经运行了Marshal.ReleaseComObject(parse32),但是以某种方式使用的内存不再减少。
我在堆栈溢出中看到建议使用的答案:-
rankdir="LR
Run Code Online (Sandbox Code Playgroud)
但他们没有处理我的这个剧本。
from graphviz import Digraph
dot = Digraph()
dot.node('A', '(3904,1) (Input)')
dot.node('B', '(3904,64) LSTM layer 1')
dot.node('C', '(3904,128) LSTM layer 2')
dot.edges(['AB', 'BC'])
dot.render("a.gv", view=True)
Run Code Online (Sandbox Code Playgroud)
如果我添加这一行:-
dot=Digraph(rankdir="LR)
Run Code Online (Sandbox Code Playgroud)
它会抛出错误,表示有向图没有名为“rankdir”的属性。
我想将垂直图转换为水平图,任何帮助将不胜感激!谢谢。
我有一个连接的组件,当用 a 包装时可以正常渲染<div>
,但是当我用 Dialog 组件包装时,我不断收到可怕的消息:在“Connect(MyComponent)”的上下文中找不到“store”。是的,根<App />
被包裹起来<Provider />
并且存储很好,所有其他页面、组件、连接的项目都可以访问存储,只是在此对话框中渲染时不能访问存储。
这在过去并不是一个问题,并且显然是由于正在发生的某些依赖项维护而产生的副作用。如果我将 Dialog 组件的底层库从 MUI 0.20 交换到版本 3(通过 @material-ui/core/Dialog),它可以正常工作。mui 0.20 和更新的 React-ish 依赖项之间存在一些平衡。
只是想知道是否有人经历过这种情况?
// Where it's invoked...
<ParentPageComp>
<Dialog open>
<MyConnectedComponent />
</Dialog>
</ParentPageComp>
// What is being attempted to render...
class MyConnectedComponent extends React.Component {
render() {
return <div>Yeppers</div>;
}
}
export default connect(state => ({ blah: state.blah }))(MyConnectedComponent);
Run Code Online (Sandbox Code Playgroud)
同样,如果我替换<Dialog>
为<div>
,一切正常。
不确定这是否相关,但是包装对话框的父组件是用钩子异步加载的......即使替换为react-loadable的代码分割机制,我也会得到同样顽皮的结果。
使用:
c++ ×2
.net ×1
arduino ×1
asp.net-core ×1
azure ×1
c ×1
c# ×1
containers ×1
data-binding ×1
dialog ×1
docker ×1
dot ×1
esp32 ×1
graphviz ×1
java ×1
javafx ×1
javascript ×1
jint ×1
junit5 ×1
kubernetes ×1
lombok ×1
material-ui ×1
mvvm-light ×1
null-pointer ×1
pointers ×1
python ×1
python-3.x ×1
react-redux ×1
redux ×1
reference ×1
scriptengine ×1
signalr ×1
sleep-mode ×1
store ×1
thread-sleep ×1
wpf ×1