PageRenderTime 25ms CodeModel.GetById 15ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/MSBuildVersioning/HgVersionTokenReplacer.cs

#
C# | 27 lines | 22 code | 2 blank | 3 comment | 0 complexity | 4ba97069aff85988787a6472fff914ed MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Text;
 4using System.Text.RegularExpressions;
 5
 6namespace MSBuildVersioning
 7{
 8    /// <summary>
 9    /// Replaces tokens in a string with information from a <c>HgInfoProvider</c>.
10    /// </summary>
11    public class HgVersionTokenReplacer : VersionTokenReplacer
12    {
13        public HgVersionTokenReplacer(HgInfoProvider infoProvider)
14        {
15            SourceControlInfoProvider = infoProvider;
16
17            AddToken("REVNUM", () => infoProvider.GetRevisionNumber().ToString());
18            AddToken("REVNUM_MOD", x => (infoProvider.GetRevisionNumber() % x).ToString());
19            AddToken("REVNUM_DIV", x => (infoProvider.GetRevisionNumber() / x).ToString());
20            AddToken("REVID", () => infoProvider.GetRevisionId());
21            AddToken("REVIDLONG", () => infoProvider.GetLongRevisionId());
22            AddToken("DIRTY", () => infoProvider.IsWorkingCopyDirty() ? "1" : "0");
23            AddToken("BRANCH", () => infoProvider.GetBranch());
24            AddToken("TAGS", () => infoProvider.GetTags());
25        }
26    }
27}