小编Caf*_*eek的帖子

使用C#自动化Photoshop

正在寻找一种使用c#代码为现有photoshop文件添加背景图层的方法?

有任何想法吗?

谢谢-c

c# photoshop

4
推荐指数
1
解决办法
9635
查看次数

VS 2008,分析多个测试

我写了一组验收测试,并试图用它们来测试库的性能.不幸的是,我似乎只能选择一个单独的测试和"创建性能会话"......这并没有给出整个应用程序性能的真实情况.

有没有办法一次性获得所有测试的性能报告?

performance unit-testing visual-studio

4
推荐指数
1
解决办法
188
查看次数

转换大型Xml文件

我正在使用此扩展方法使用xslt转换非常大的xml文件.

不幸的是,我在source.ToString()行上得到了一个OutOfMemoryException.

我意识到必须有一个更好的方法,我只是不确定那会是什么?

public static XElement Transform(this XElement source, string xslPath, XsltArgumentList arguments)
{
        var doc = new XmlDocument();
        doc.LoadXml(source.ToString());

        var xsl = new XslCompiledTransform();
        xsl.Load(xslPath);

        using (var swDocument = new StringWriter(System.Globalization.CultureInfo.InvariantCulture))
        {
            using (var xtw = new XmlTextWriter(swDocument))
            {
                xsl.Transform((doc.CreateNavigator()), arguments, xtw);
                xtw.Flush();
                return XElement.Parse(swDocument.ToString());
            }
        }
}
Run Code Online (Sandbox Code Playgroud)

思考?解决方案?等等.

更新:现在这已经解决了,我在验证架构时遇到了问题! 验证大型Xml文件

c# xml xslt out-of-memory

4
推荐指数
1
解决办法
3228
查看次数

Damerau - Levenshtein距离,增加一个门槛

我有以下实现,但我想添加一个阈值,所以如果结果将大于它,只需停止计算并返回.

我该怎么办呢?

编辑:这是我目前的代码,threshold尚未使用...目标是它被使用

    public static int DamerauLevenshteinDistance(string string1, string string2, int threshold)
    {
        // Return trivial case - where they are equal
        if (string1.Equals(string2))
            return 0;

        // Return trivial case - where one is empty
        if (String.IsNullOrEmpty(string1) || String.IsNullOrEmpty(string2))
            return (string1 ?? "").Length + (string2 ?? "").Length;


        // Ensure string2 (inner cycle) is longer
        if (string1.Length > string2.Length)
        {
            var tmp = string1;
            string1 = string2;
            string2 = tmp;
        }

        // Return trivial case - where string1 is …
Run Code Online (Sandbox Code Playgroud)

c# levenshtein-distance threshold

4
推荐指数
1
解决办法
4779
查看次数

在XSLT中将24小时时间转换为12小时时间

转换小时似乎需要做很多工作......必须有一个更简单的方法.

  <xsl:variable name="hour12">
    <xsl:choose>
      <xsl:when test="$hour24 &lt; 0">
        <xsl:value-of select="12 + $hour24" />
      </xsl:when>
      <xsl:when test="$hour24 = 0">
        <xsl:value-of select="12" />
      </xsl:when>
      <xsl:when test="$hour24 = 12">
        <xsl:value-of select="$hour24" />
      </xsl:when>
      <xsl:when test="$hour24 &gt; 12">
        <xsl:value-of select="$hour24 - 12" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$hour24" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:variable>
Run Code Online (Sandbox Code Playgroud)

有什么建议?

xslt

4
推荐指数
1
解决办法
2243
查看次数

在 Java 中使用 Kotlin Value 类

我们有两个项目,kotlin 项目发布了一个由 java 导入的包。

在 kotlin 中,是一个像这样的值类

@JvmInline
value class CountryId(private val id: UUID) {
    override fun toString(): String = id.toString()
    companion object { fun empty(): CountryId = CountryId(EMPTY_UUID) }
}
Run Code Online (Sandbox Code Playgroud)

在java中,我们看不到构造函数,也看不到实际实例化这个类。我还尝试在 Kotlin 中创建一个工厂来创建它们

class IdentifierFactory 
{
    companion object {
        fun buildString(): String {
            return "hello"
        }

        fun buildCountry(): CountryId {
            return CountryId.empty()
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

在java中,我可以调用IdentifierFactory.Companion.buildString()它并且它会工作,但它IdentifierFactory.Companion.buildCountry()甚至不存在。

Java 的 Value 类真的这么糟糕吗?

附:我也尝试过@JvmStatic,但没有成功

pps。如果我从java端反编译kotlin字节码,并得到一个CountryId.decompiled.java,这就是构造函数的样子

// $FF: synthetic method
private CountryId(UUID id) {
    Intrinsics.checkNotNullParameter(id, "id");
    super();
    this.id = …
Run Code Online (Sandbox Code Playgroud)

java kotlin value-class

4
推荐指数
1
解决办法
2212
查看次数

正则表达式不够贪心

我有以下正则表达式,在新情况出现之前完美运行

^.*[?&]U(?:RL)?=(?<URL>.*)$
Run Code Online (Sandbox Code Playgroud)

基本上,它用于对抗URL,在U =或URL =之后获取一切,并在URL匹配中返回它

所以,对于以下内容

HTTP://本地主机A = B&U = HTTP:// OTHERHOST富=酒吧

URL = http:// otherhost?foo = bar

不幸的是,出现了奇怪的情况

HTTP://本地主机A = B&U = HTTP:// OTHERHOST富=栏&URL = HTTP:// someotherhost

理想情况下,我希望URL为" http:// otherhost?foo = bar&url = http:// someotherhost ",相反,它只是" http:// someotherhost "

编辑:我认为这解决了它...虽然它不漂亮

^.*[?&](?<![?&]U(?:RL)?=.*)U(?:RL)?=(?<URL>.*)$
Run Code Online (Sandbox Code Playgroud)

regex language-agnostic regex-greedy

3
推荐指数
1
解决办法
627
查看次数

jQuery选择具有多个类的元素

我需要选择包含多个类的所有元素.类名无关紧要,我只需要选择两个或更多的元素.

这个jQuery选择器会是什么样的?

jquery jquery-selectors

3
推荐指数
1
解决办法
748
查看次数

茉莉花 .toHaveBeenCalledWith(aDate) 不工作

我正在继承一些代码,我有两个他们的测试仍然失败,不确定它们是不是以前的,或者是因为我有不同版本的 Jasmine(它们是 2.0 之前的)

失败的测试在 beforeEach 中有这个间谍设置

spyOn(datacontext, 'getImportLogForDate').and.callThrough();
Run Code Online (Sandbox Code Playgroud)

然后在测试中

controller.DepositDate = new Date();
controller.PerformActionThatCallsGetImportLogForDate();
expect(context.getImportLogForDate).toHaveBeenCalledWith('1', controller.DepositDate);
Run Code Online (Sandbox Code Playgroud)

由此产生的错误令人困惑,因为它们是相同的

预期 spy getImportLogForDate 已被调用['1', Date(Thu Dec 04 2014 13:00:51 GMT-0600 (Central Standard Time))]但实际调用是['1', Date(Thu Dec 04 2014 13) :00:51 GMT-0600(中部标准时间))]

我不能验证使用日期调用的函数吗?

testing jasmine

3
推荐指数
1
解决办法
3232
查看次数

Expression.IsFalse是未知的?

我最终尝试运行查询时收到以下错误

"IsFalse"类型的未知LINQ表达式

这是代码

private static IQueryable<T> QueryMethod<T>(
    IQueryable<T> query,
    QueryableRequestMessage.WhereClause.Rule rule,
    Type type,
    string methodName,
    Expression property,
    Expression value,
    string op,
    ParameterExpression parameter
) where T : class
{
    var methodInfo = type.GetMethod(methodName, new[] { type });
    var call = Expression.Call(property, methodInfo, value);
    var expression = rule.Op.Equals(op)
                            ? Expression.Lambda<Func<T, bool>>(call, parameter)
                            : Expression.Lambda<Func<T, bool>>(Expression.IsFalse(call), parameter);
    query = query.Where(expression);
    return query;
}
Run Code Online (Sandbox Code Playgroud)

重要变量具有以下值

query: an IQueryable that I am building up
type: String
methodName: "EndsWith"
rule.Op: "ne" //Not Ends With
op: …
Run Code Online (Sandbox Code Playgroud)

linq expression-trees

2
推荐指数
1
解决办法
391
查看次数