Question

I am converting a minification function from visual basic:

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

to c#. However, the compress method in c# only takes a string argument and has no overload methods. Is the below code in c# equivalent to the original VB code above?

var compressor = new Yahoo.Yui.Compressor.JavaScriptCompressor();
example = compressor.Compress(someString);
Was it helpful?

Solution

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. 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.

OTHER TIPS

You are calling the static Yahoo.Yui.Compressor.JavaScriptCompressor.Compress method in VB.NET and instanciating a Yahoo.Yui.Compressor.JavaScriptCompressor class in C#.

You can call Yahoo.Yui.Compressor.JavaScriptCompressor.Compress in C# to reproduce the same behavior.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top