有什么方法可以找出整个隐含链(我对所有隐含的类感兴趣).我正在使用IntelliJ Idea,但我正在寻找任何方法来做到这一点,即使我必须使用另一个IDE.(我想知道REPL是否可以帮助我)
例如,我写的是来自a gt b哪里.我想知道:gtscalaz
Order使用a收到一个方法gt.对于这个特殊的例子,我知道使用了ToOrderOps特性,但总的来说我可能不知道,我也无法弄清楚是如何ToOrderOps导入的.我有一个这个行的bash脚本:
cp -R /usr/lib/gcc/x86_64-linux-gnu/$GCC_VERSION/* /app/.apt/usr/lib/gcc/x86_64-linux-gnu/$GCC_VERSION
Run Code Online (Sandbox Code Playgroud)
完整脚本:https://github.com/virtualstaticvoid/heroku-buildpack-r/blob/cedar-14/bin/compile
不幸的是它失败了 cp: target ‘/app/.apt/usr/lib/gcc/x86_64-linux-gnu/4.8’ is not a directory
什么提示可能是错的?不幸的是,我对bash没有多少经验.
以前这个脚本是单独运行的,它正在运行.现在我必须apt-get install在它之前添加一些,它开始失败所以我试图解决它.
我通过继承DelegatingHandler并将类添加为实现了基于JWT的身份验证configuration.MessageHandlers.Add(new MyDelegatingHandler())。
实施时DelegatingHandler,我优先Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)。那里的逻辑很简单-我从Authorization标头中检索令牌,检查其有效性。如果有效-我设置Thread.CurrentPrincipal和HttpContext.Current.User,否则返回new HttpResponseMessage(HttpStatusCode.Unauthorized)
基本上看起来像这样(非常简化):
public class TokenValidationHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var token = GetTokenFromAuthorizeHeader(request);
if (TokenIsValid(token)) {
var principal = CreatePrincipal(token);
Thread.CurrentPrincipal = principal;
HttpContext.Current.User = principal;
return base.SendAsync(request, cancellationToken);
} else {
// TODO: fix
return Task<HttpResponseMessage>.Factory.StartNew(() => new HttpResponseMessage(HttpStatusCode.Unauthorized));
}
}
}
Run Code Online (Sandbox Code Playgroud)
现在,甚至在具有[AllowAnonymous]属性的WebApi方法上也调用此方法。这很好,因为即使该方法允许匿名,我也想设置主体。但是,如果Authorization标头中提供的令牌无效,则此逻辑将失败。
用户使用标头中[AllowAnonymous]带有无效令牌的资源向资源发送请求, …
我有一个承诺,处理通过Web API执行的HTTP请求:
promise = promise.then(r => {
// ...
}, error => {
if (error.status == 404) {
// Here I can fix an error and continue properly
} else {
// Here the error should be propagated further in the promise
}
}
// later in the code:
promise.catch(r => { /* More error handling */ } );
Run Code Online (Sandbox Code Playgroud)
在代码的后面,这个承诺被链接到更多的错误检查.
在404错误的情况下,我实际上可以"修复"一个问题,我不希望其他处理程序触发.在这种情况下,我宁愿让这个承诺成功.我怎样才能做到这一点?
更多代码可以更深入地解释我的案例:
refresh() {
this.refreshAsync().catch(r => {
// Show error to the user.
notifications.showError("Unexpected error happened");
});
}
async refreshAsync() …Run Code Online (Sandbox Code Playgroud) 我们正在制定一个框架并将消息来源出售给客户.昨天有一位客户报告称由于道路太长,他无法建立源头.我发现源中最长的路径是NuGet产生的路径,它是:
project\packages\EnterpriseLibrary.ExceptionHandling.Logging.5.0.505.0\lib\NET35\Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll.
连同客户放置源的文件夹名称(不是很长,大约90个字符),以及奇怪的VS行为,当它组成绝对路径c:\blablabla... ..\..\..\something超过260个字符时,他的VS无法编译解决方案.
无论如何我可以解决这个问题?我无法要求客户将源更靠近磁盘根目录 - 他对将代码放在公司内部的位置有自己的协议.我也可以重命名这个dll,但我不想放弃NuGet的支持.
这是我第二次尝试定义问题,我无法理解它.
我想能够定义一个代数类型并在其上定义一个简单的类型类,比方说Show.在哈斯克尔我做:
data Tree a = EmptyTree | Node a deriving (Show)
Run Code Online (Sandbox Code Playgroud)
现在,如果我输入EmptyTree- haskell可以显示它,所以它属于Show.
现在我想在scala中做同样的事情:
sealed abstract class Tree[+T]
case object EmptyTree extends Tree[Nothing]
case class Node[T](value: T) extends Tree[T]
Run Code Online (Sandbox Code Playgroud)
然后我定义Show它:
implicit def show[T] = Show.showA[Tree[T]]
Run Code Online (Sandbox Code Playgroud)
我能做到println((EmptyTree : Tree[Int]).show).但我做不到println(EmptyTree.show)(回应是value show is not a member of object EmptyTree)
我必须写更多:
implicit class MyShowOps[A, +T <: Tree[A]](t: T) {
def showMy(implicit ev: Show[Tree[A]]): String = ev.shows(t)
}
Run Code Online (Sandbox Code Playgroud)
只有这样我才能做到 println(EmptyTree.showMy) …
有什么方法可以让 automapper 不克隆同一个对象,而是在层次结构中多次遇到它时使用单个对象?
基本上,我有一大堆不同的对象,它们都引用同一个对象。当我使用 AutoMapper 映射此集合时,它会生成一个对象数组,其中每个对象都引用一个新的克隆对象。所有这些克隆对象不再通过引用相等。这最终导致了我的内存不足问题。
有没有办法为 AutoMapper 配置某种缓存?
我已经尝试.PreserveReferences()过 AutoMapper 配置,但这并没有达到我想要的效果。我认为这仅适用于循环引用。
更新。
我测试的代码示例.PreserveReferences()。
[TestMethod]
public void TestMethod1()
{
Mapper.Initialize(cfg =>
{
cfg.CreateMap<A, MA>().PreserveReferences();
cfg.CreateMap<B, MB>();
});
var b = new B();
var a1 = new A() { Ref = b };
var a2 = new A() { Ref = b };
Assert.AreNotSame(a1, a2);
Assert.AreSame(a1.Ref, a2.Ref);
var ma1 = Mapper.Map<MA>(a1);
var ma2 = Mapper.Map<MA>(a2);
Assert.AreNotSame(ma1, ma2);
Assert.AreSame(ma1.Ref, ma2.Ref); // This fails.
}
class A { public …Run Code Online (Sandbox Code Playgroud) 我有一个绑定在对象上的组件,并且父组件更改其对象的属性。子组件应对更改做出反应。
子组件:
import { Component, Emit, Inject, Model, Prop, Provide, Vue, Watch } from 'vue-property-decorator'
@Component({
props: {
value: Object,
}
})
class ValidatedSummaryComponent extends Vue {
value: any;
field = "Name";
v: any;
created() {
console.log("!", this.value);
this.v = this.value;
}
state: string | null = null;
error = "";
@Watch('value')
onValueChanged(val: any, oldVal: any) {
console.log("Value called", val);
this.v = val;
this.onChanged();
this.$forceUpdate();
}
private onChanged() {
if (typeof this.v.validationErrors[this.field] == 'undefined') {
this.state = null;
this.error = …Run Code Online (Sandbox Code Playgroud) I'm trying to augment vue js with additional mapping. I'm following this: https://v2.vuejs.org/v2/guide/typescript.html#Augmenting-Types-for-Use-with-Plugins
I have created a file vue.d.ts under ./Definitions (relative to my main.ts)
I have referenced it in my main.ts:
require("./Definitions/vue.d.ts");
Run Code Online (Sandbox Code Playgroud)
In vue.d.ts I've put:
// 1. Make sure to import 'vue' before declaring augmented types
import Vue from 'vue'
// 2. Specify a file with the types you want to augment
// Vue has the constructor type in types/vue.d.ts
declare module 'vue/types/vue' {
// 3. …Run Code Online (Sandbox Code Playgroud) 如果我写这个:
val (x, y) = (Some(8), None)
def f(x: Int, y: Int) = x + y
for {x0 <- x; y0 <- y} yield f(x0, y0)
Run Code Online (Sandbox Code Playgroud)
我收到了预期的结果: res5: Option[Int] = None
但如果我试着写:
for {x0 <- x; y0 <- y} yield (x0 + y0)
Run Code Online (Sandbox Code Playgroud)
我收到下一个错误:
<console>:10: error: ambiguous reference to overloaded definition,
both method + in class Int of type (x: Char)Int
and method + in class Int of type (x: Byte)Int
match argument types (Nothing)
for {x0 <- x; y0 …Run Code Online (Sandbox Code Playgroud) 我正在尝试迭代地构建我的数据的所有可能的图表,由表格中的每一列着色.
到目前为止,我有这个代码:
# ----- next is a function taken from http://www.cookbook-r.com/Graphs/Multiple_graphs_on_one_page_(ggplot2)/
# --- not relevant to the question, my code is in the end of the snippet
library(ggplot2)
multiplot <- function(..., plotlist=NULL, file, cols=1, layout=NULL) {
library(grid)
# Make a list from the ... arguments and plotlist
plots <- c(list(...), plotlist)
numPlots = length(plots)
# If layout is NULL, then use 'cols' to determine layout
if (is.null(layout)) {
# Make the panel
# ncol: Number of columns of plots
# …Run Code Online (Sandbox Code Playgroud) c# ×3
scala ×3
typescript ×3
vue.js ×3
automapper ×1
bash ×1
heroku ×1
ibm-cloud ×1
javascript ×1
msbuild ×1
nuget ×1
promise ×1
r ×1
scalaz ×1