Search code examples
c#vb.netyui

YUI Compression VB vs C#


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);

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.