以下是人为的,但请耐心等待:
interface Clonable<TSubClass>
{
TSubClass Clone();
}
Run Code Online (Sandbox Code Playgroud)
如何将TSubClass限制为实现类型?
即只让实现者这样做:
class Dog : Clonable<Dog>
{
Dog Clone()
{
....
}
}
Run Code Online (Sandbox Code Playgroud)
不是这个:
class BadDog : Clonable<Rabbit>
{
Rabbit Clone()
{
....
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个包含多个C#6.0项目的.NET解决方案。每个项目都通过NuGet引用StyleCop Analyzer。在Visual Studio中,我可以区分构建和分析代码,但是我看不到如何在命令行上(例如,在CI服务器上)使用MSBuild v14.0做到这一点。我打电话msbuild mySolution.sln /t:Rebuild给以下选项,它们都不起作用:
/p:RunCodeAnalysis=False/p:RunCodeAnalysisOnThisProject=False/p:RunCodeAnalysis=False,RunCodeAnalysisOnThisProject=False无论我做什么,警告SAxxxx都会保留在输出中。有谁知道如何在使用MSBuild时禁用代码分析?
背景:在我们的CI服务器上,我想区分“基本MSBuild警告”和来自静态代码分析的警告。
问候
如何or在不允许重复的情况下使用操作符?换句话说正则表达式:
(word1|word2|word3)+
Run Code Online (Sandbox Code Playgroud)
会匹配, word1word2但也会匹配word1word1我不想要的,因为word1正在重复.我该如何避免重复?
总之,我希望以下主题匹配:
word1word2word3
word1
word2
word3word2
Run Code Online (Sandbox Code Playgroud)
注意它们都匹配,因为没有重复.我希望以下主题失败:
word1word2word1
word2word2
word3word1word2word2
Run Code Online (Sandbox Code Playgroud)
感谢@Mark 我知道:
(?xi)
(?:
(?<A>word1|word2)(?! .* \k<A> ) # match for word1 or word2 but make sure that if you capture it it does not follow what it was just captured
| (?<B>word3|word4)(?! .* \k<B> )
)+
Run Code Online (Sandbox Code Playgroud)
因为我有兴趣看看是否在A组或B组中捕获了某些东西.
我们可能知道,例如customErrors和httpErrors有什么区别?,CustomErrors是一种在Web应用程序中定义错误页面的旧方法,但这种方法存在一些问题 - 例如,如果您关心正确的http响应代码,因为CustomErrors的方法是重定向到错误页面而不是替换当前响应,它通过http状态代码破坏了通信的大部分语义完整性.
自IIS 7.0以来,HttpErrors是一个更新的功能,它在服务器级而不是应用程序级运行,并且更适合以有效的方式处理错误响应,例如通过使用当前响应而不是重定向.
但是,如果在我看来,ASP.NET中这些工件的基础结构如今看起来给我们带来了一些问题.
一个简单的配置作为例子
<httpErrors existingResponse="Auto" errorMode="Custom">
<remove statusCode="404"/>
<error statusCode="404" path="/Error/E404" responseMode="ExecuteURL" />
</httpErrors>
Run Code Online (Sandbox Code Playgroud)
我们将errorMode设置为Custom,因为我们要测试错误处理本身,并将existingResponse设置为Auto,这将引入依赖于Response.TrySkipIisCustomErrors的分支:
理想情况下,这将允许我们自己处理一些错误,例如当../product/id中的产品不存在时,我们可以手动返回特定的404页面,其中包含有关缺失产品的信息,并且仍然让HttpErrors模块处理所有错误像..产品 /名称,但是只是../misspelledandunmatchableurl.
但是,据我所知,这是行不通的.原因在于内部方法System.Web.HttpResponse .ReportRuntimeError,它将在运行时错误(例如未找到控制器/操作)上调用,并且我们有一个如下所示的部分:
// always try to disable IIS custom errors when we send an error
if (_wr != null) {
_wr.TrySkipIisCustomErrors = true;
}
if (!localExecute) {
code = HttpException.GetHttpCodeForException(e);
// …Run Code Online (Sandbox Code Playgroud) 我有一个扩展的typescript类React.Component:
class MyComponent extends React.Component<{}, {}>
{
constructor(props: {})
{
super(props);
}
public render()
{
return <span>Test</span>;
}
public MyMethod() {
console.log("Working fine");
}
}
Run Code Online (Sandbox Code Playgroud)
然后有一个地方我手动创建一个实例并将其附加到DOM:
var component = MyComponent;
var element = React.createElement(component, {}, null);
ReactDOM.render(element, myDomElementContainer);
Run Code Online (Sandbox Code Playgroud)
由于系统的体系结构限制,我需要存储对该组件的类实例的引用供以后使用,问题是我在创建的元素中找不到对我的类实例的任何引用,它只有一个引用通过酒店到班上type.
React.createElement只允许我提供类,ReactDOM.render而不喜欢手动实例化的对象.
我应该如何实例化自定义组件,将其附加到DOM并获取对组件类实例的引用?
获取对象的原型很容易,但有没有办法获得具有特定原型的所有实例?
像这样的东西:
var allAnimals = Animal.prototype.getInstances();
Run Code Online (Sandbox Code Playgroud)
可以编写自定义代码来跟踪实例化对象,但我对是否有任何内置方法感兴趣.
关于它有一些关于它的问题,但不幸的是它们似乎都被弃用了.
我使用angular2与angular-cli.
要使用安装d3.js即可npm install d3.
我的app.component.ts档案:
import { Component } from '@angular/core';
import * as d3 from 'd3';
@Component({
selector: 'app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
}
Run Code Online (Sandbox Code Playgroud)
但不知何故,由于错误,应用程序无法正确加载:
Cannot find module 'd3'.
这有点奇怪,特别是因为Webstorm能够看到文件并且不会报告任何问题.
我也尝试安装c3.js库,安装ive之后尝试了相同的导入方式:
npm install c3
和
import * as c3 from 'c3';
但它和第一个一样不起作用.
编辑!
使用命令后:
npm install d3 --save
npm install @types/d3 --save-dev
就像@Tudor Ciotlos提到的那样,我得到的错误很少.
[默认] C:\ Users \node_modules\@types\c3\index.d.ts:28:41泛型类型'Selection'需要4个类型的参数.[默认] C:\ Users \node_modules\@types\c3\index.d.ts:351:56
模块'"C:\ Users \node_modules/@ types/d3/index"'没有导出成员'Rgb'.[默认] C:\ Users …
我正在阅读OOP设计模式和框架设计,发现自己对术语ORM和Persistence framework之间的区别不太了解。ORM是PF的一种吗?您可以期望这两种功能有哪些不同?
我在数据表中有一个很大的 IP 地址列表,我必须如此快速地对它们执行 ping 操作,我使用了以下代码:
public bool PingIP(string IP)
{
bool result = false;
try
{
Ping ping = new Ping();
PingReply pingReply = ping.Send(IP);
if (pingReply.Status == IPStatus.Success)
result = true;
}
catch
{
result = false;
}
return result;
}
Run Code Online (Sandbox Code Playgroud)
然后我在 while 循环中调用它:
private void CheckNetworkState()
{
while (rowindexping > -1)
{
if (rowindexping == tbl_ClientInfo.Rows.Count)
{
rowindexping = -1;
return;
}
string ip = tbl_ClientInfo.Rows[rowindexping]["clientip"].ToString();
if (!PingIP(ip))
{
do something
}
rowindexping++;
Thread.Sleep(100);
}
}
Run Code Online (Sandbox Code Playgroud)
因为我想在项目的后台完成这项工作,所以我在线程中调用该类:
threadping …Run Code Online (Sandbox Code Playgroud) c# multithreading thread-safety visual-studio-2010 visual-studio
考虑这个失败的例子:
function DecorateClass<T>(instantiate: (...params:any[]) => T){
return (classTarget:T) => { /*...*/ }
}
@DecorateClass((json:any) => {
//Purely example logic here, the point is that it have to return
//an instance of the class that the decorator runs on.
var instance = new Animal();
instance.Name = json.name;
instance.Sound = json.sound;
return instance;
})
class Animal {
public Name:string;
public Sound:string;
}
Run Code Online (Sandbox Code Playgroud)
在这里,我想约束装饰器中的匿名函数,以便始终返回有问题的类的实例,但由于T实际上typeof Animal没有,因此上述方法不起作用Animal.
在一个泛型函数中,无论如何我可以从类型中Animal获取类型typeof Animal而不会像显式定义所有类型那样令人讨厌冗长function DecorateClass<TTypeOfClass, TClass>(...)吗?
不幸的是,不支持在通用语法中使用typeof,这是我试图让编译器理解我想要的东西的最佳选择:
function …Run Code Online (Sandbox Code Playgroud) c# ×4
javascript ×2
typescript ×2
.net ×1
angular ×1
asp.net ×1
asp.net-mvc ×1
d3.js ×1
generics ×1
iis ×1
msbuild ×1
msbuild-14.0 ×1
orm ×1
parameters ×1
prototype ×1
reactjs ×1
regex ×1
restrictions ×1