Skip to content

Commit

Permalink
Separated pragma/ReSharper disable&restore, restore to bottom of file
Browse files Browse the repository at this point in the history
  • Loading branch information
devlead committed Dec 1, 2014
1 parent c28b935 commit 691da64
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions T4/IncludeHeader.ttinclude
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
{
var includeMatch = s_matchInclude.Match (line);
var topMatch = s_matchMoveToTop.Match (line);
var bottomMatch = s_matchMoveToBottom.Match (line);
if (includeMatch.Success)
{
var fileName = includeMatch.Groups["fileName"].Value;
Expand All @@ -91,10 +92,14 @@
{
include.TopLines.Add (line);
}
else
else if (bottomMatch.Success)
{
include.BottomLines.Add (line);
}
else
{
include.MiddleLines.Add (line);
}
}
}
catch (Exception exc)
Expand Down Expand Up @@ -148,14 +153,14 @@ namespace <#=Namespace#>
<#
}

foreach (var bottomLine in include.BottomLines)
foreach (var middleLine in include.MiddleLines)
{
if (hasNamespace)
{
Write (" ");
}

WriteLine (bottomLine);
WriteLine (middleLine);
}
if (hasNamespace)
{
Expand All @@ -169,7 +174,16 @@ namespace <#=Namespace#>
<#
}
#>

// ############################################################################
// Certains directives such as #define and // Resharper comments has to be
// moved to bottom in order to work properly
// ############################################################################
<#
foreach (var bottomLine in processed.SelectMany(i => i.BottomLines).Distinct ().OrderBy (p => p))
{
WriteLine (bottomLine);
}
#>
// ############################################################################
<#
if (string.IsNullOrEmpty (Namespace))
Expand Down Expand Up @@ -224,10 +238,13 @@ namespace <#=Namespace#>.Include
);

static readonly Regex s_matchMoveToTop = new Regex (
@"^(\#define|\#pragma|// ReSharper )",
@"^(\#define|\#pragma warning disable|// ReSharper disable )",
RegexOptions.IgnoreCase | RegexOptions.Compiled |RegexOptions.CultureInvariant |RegexOptions.Singleline
);
static readonly Regex s_matchMoveToBottom = new Regex (
@"^(\#define|\#pragma warning restore|// ReSharper restore )",
RegexOptions.IgnoreCase | RegexOptions.Compiled |RegexOptions.CultureInvariant |RegexOptions.Singleline
);

class BlackListedFileFragment
{
public string Fragment;
Expand All @@ -248,6 +265,7 @@ namespace <#=Namespace#>.Include

public string FullPath ;
public List<string> TopLines = new List<string> ();
public List<string> MiddleLines = new List<string> ();
public List<string> BottomLines = new List<string> ();
}

Expand All @@ -271,4 +289,4 @@ namespace <#=Namespace#>.Include
}


#>
#>

0 comments on commit 691da64

Please sign in to comment.