Advent LINQ (1): SplitAsEnumerable

System.Stringクラスには、Splitというメソッドがある。引数で指定された文字で文字列を分割するメソッドなのだが、返却される結果は配列になっている。配列と言う事は、非常に多くの文字列が分割されると、それだけメモリを消費する事になる。
そんなわけで、このメソッドを逐次実行可能な列挙子を返すLINQメソッドとして定義してみる。

public static class LinqExtensions
{
    public static IEnumerable<string> SplitAsEnumerable(this string target, params char[] separators)
    {
        var startIndex = 0;
        while (true)
        {
            var index = target.IndexOfAny(separators, startIndex);
            if (index == -1)
            {
                yield return target.Substring(startIndex);
                break;
            }

            yield return target.Substring(startIndex, index - startIndex);
            startIndex = index + 1;
        }
    }
}

System.String.Splitはインスタンスメンバーなので、Splitというメソッド名にすると呼び出せなくなってしまう。仕方がないので、SplitAsEnumerableという名前で定義した。

var veryLongStringValue = "...";
foreach (var value in veryLongStringValue.SplitAsEnumerable(','))
{
    Console.WriteLine("Value={0}", value);
}

これで逐次分割できるようになった。ロジックを拡張して、ダブルクオートで囲まれた文字列を切り出す等の応用が出来ると思う。

Visual Studio Coverage file to Emma converter

CodePlex now!
And 1.0.1.0 released!!

Visual Studio Coverage file to Emma converter : CodePlex


Visual Studio Coverage file to Emma converter.
Simple solution, can apply only one tool to five Visual Studio versions.
Fast multicore processing.

Included:

  • Command line executable.
  • MSBuild custom task.

Thank you choosing this tool, probably use with jenkins.
(I’m not jenkins professional ops, may not operate this tool…)

Require:
.NET Framework 4.5.1 Runtime environment.
Visual Studio 2005, 2008, 2010, 2012 and/or 2013 versions (Require code coverage option)

Setup:
1. Copy VSCoverageToEmma.exe, VSCoverageToEmma.dll to your tool folder.
2. Copy VS
folders (ex:VS2013) to your tool folder.
3. Copy your Visual Studio’s “Microsoft.VisualStudio.Coverage..dll”
(In %VSROOTFOLDER%Common7IDEPrivateAssemblies) into VS
folders.

Tool folder example:

  Tool
    +--- VSCoverageToEmma.exe
    +--- VSCoverageToEmma.Interfaces.dll
    +--- VSCoverageToEmma.Core.dll
    +--- VSCoverageToEmma.VS2005Converter.dll
    +--- VSCoverageToEmma.VS2008Converter.dll
    +--- VSCoverageToEmma.VS2010Converter.dll
    +--- VSCoverageToEmma.VS2012Converter.dll
    +--- VSCoverageToEmma.VS2013Converter.dll
    +--- VS2005
    |       +--- Microsoft.VisualStudio.Coverage.Analysis.dll (From Visual Studio 2005, if use)
    +--- VS2008
    |       +--- Microsoft.VisualStudio.Coverage.Analysis.dll (From Visual Studio 2008, if use)
    +--- VS2010
    |       +--- Microsoft.VisualStudio.Coverage.Analysis.dll (From Visual Studio 2010, if use)
    |       +--- Microsoft.VisualStudio.Coverage.Interop.dll  (From Visual Studio 2010, if use)
    |       +--- Microsoft.VisualStudio.Coverage.Symbols.dll  (From Visual Studio 2010, if use)
    +--- VS2012
    |       +--- Microsoft.VisualStudio.Coverage.Analysis.dll (From Visual Studio 2012, if use)
    |       +--- Microsoft.VisualStudio.Coverage.Interop.dll  (From Visual Studio 2012, if use)
    |       +--- Microsoft.VisualStudio.Coverage.Symbols.dll  (From Visual Studio 2012, if use)
    +--- VS2013
            +--- Microsoft.VisualStudio.Coverage.Analysis.dll (From Visual Studio 2013, if use)
            +--- Microsoft.VisualStudio.Coverage.Interop.dll  (From Visual Studio 2013, if use)
            +--- Microsoft.VisualStudio.Coverage.Symbols.dll  (From Visual Studio 2013, if use)

Command line usage (VS2013):

  C:TEMPVSCoverageToEmmaDebug&gt;VSCoverageToEmma.exe VS2013 &quot;C:TEMPCoverageTargetTestResults&quot; &quot;C:TEMPCoverageTargetbinDebug&quot; &quot;C:TEMPCoverageTargetbinDebug&quot; &quot;C:TEMPCoverageTargetTestResults&quot;

If use VS2010/VS2012/VS2013 converter, automatically recursive search binary/symbol files in nested folders.

MSBuild usage:
Target assembly is “VSCoverageToEmma.Core.dll”, task name is “VSCoverageToEmma”.
ConverterName: required (ex: “VS2005”)
VSCoverageFolderPath: required (path)
BinariesFolderPath: optional (path)
SymbolsFolderPath: optional (path)
EmmaFolderPath: optional (path)
VSCoverageFiles: output (path list)
EmmaFiles: output (path list)
Methods: output (number)

MSBuild limitation: Tool execution failed in 64bit process. (VS Coverage library required 32bit mode)

Download from SkyDrive: VSCoverageToEmma-1.0.zip