简体   繁体   English

YUI压缩VB与C#

[英]YUI Compression VB vs C#

I am converting a minification function from visual basic: 我正在从Visual Basic转换一个缩小功能:

example = Yahoo.Yui.Compressor.JavaScriptCompressor.Compress(someString, False, True, True, True, -1, UTF8Encoding.UTF8, Globalization.CultureInfo.InvariantCulture)

to c#. 到C#。 However, the compress method in c# only takes a string argument and has no overload methods. 但是,c#中的compress方法仅采用字符串参数,没有重载方法。 Is the below code in c# equivalent to the original VB code above? 下面的c#代码是否等效于上面的原始VB代码?

var compressor = new Yahoo.Yui.Compressor.JavaScriptCompressor();
example = compressor.Compress(someString);

The equivalent in C#, as far as I can tell from the source , would require you to set the respective properties in the JavaScriptCompressor instance yourself instead of passing them to the (seemingly non-existent) static Compress method. 据我从源头可以得知,C#中的等效项要求您自己在JavaScriptCompressor实例中设置相应的属性,而不是将它们传递给(似乎不存在的) static Compress方法。 For example: 例如:

var compressor = new Yahoo.Yui.Compressor.JavaScriptCompressor
{
    Encoding = UTF8Encoding.UTF8,
    DisableOptimizations = false,
    ObfuscateJavascript = true,
    PreserveAllSemicolons = true,
    IgnoreEval = true,
    ThreadCulture = Globalization.CultureInfo.InvariantCulture
};

var example = compressor.Compress(someString);

The Boolean properties may not be in the same order as they were previously, so I just guessed. 布尔属性可能与以前的顺序不同,所以我猜到了。 There's a JavaScriptCompressorConfig class in the library with these properties but I couldn't find how it would get passed to the compressor. 库中有一个带有这些属性的JavaScriptCompressorConfig类,但是我找不到如何将其传递给压缩器。

You are calling the static Yahoo.Yui.Compressor.JavaScriptCompressor.Compress method in VB.NET and instanciating a Yahoo.Yui.Compressor.JavaScriptCompressor class in C#. 您正在VB.NET中调用静态Yahoo.Yui.Compressor.JavaScriptCompressor.Compress方法,并在C#中实例化Yahoo.Yui.Compressor.JavaScriptCompressor类。

You can call Yahoo.Yui.Compressor.JavaScriptCompressor.Compress in C# to reproduce the same behavior. 您可以在C#中调用Yahoo.Yui.Compressor.JavaScriptCompressor.Compress以重现相同的行为。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM