Skip to content

Commit

Permalink
Merge pull request #18 from dansiegel/pragma-warnings
Browse files Browse the repository at this point in the history
allow Pragma warning disable
  • Loading branch information
dansiegel authored Dec 16, 2020
2 parents aaf9ca7 + f47a8af commit a80b741
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/CodeGenHelpers/BuilderBase.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
namespace CodeGenHelpers
using System.Collections.Generic;
using System.Linq;

namespace CodeGenHelpers
{
public abstract class BuilderBase : IBuilder
{
protected readonly List<string> _pragmaWarnings = new List<string>();

internal abstract void Write(ref CodeWriter writer);

void IBuilder.Write(ref CodeWriter writer) =>
void IBuilder.Write(ref CodeWriter writer)
{
var warnings = string.Join(", ", _pragmaWarnings.Distinct());
if(_pragmaWarnings.Any())
{
writer.AppendUnindentedLine($"#pragma warning disable {warnings}");
}

Write(ref writer);

if (_pragmaWarnings.Any())
{
writer.AppendUnindentedLine($"#pragma warning restore {warnings}");
}
}
}
}
5 changes: 5 additions & 0 deletions src/CodeGenHelpers/BuilderBase{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public abstract class BuilderBase<T> : BuilderBase
public abstract T AddNamespaceImport(ISymbol symbol);
public abstract T AddNamespaceImport(INamespaceSymbol symbol);
public abstract T AddAssemblyAttribute(string attribute);
public T DisableWarning(string buildCode)
{
_pragmaWarnings.Add(buildCode);
return this as T;
}
}
}
1 change: 1 addition & 0 deletions src/CodeGenHelpers/CodeGenHelpers.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Compile Include="$(MSBuildThisFileDirectory)AccessibilityExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)BuilderBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)BuilderBase{T}.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CompilerWarnings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ClassBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CodeBuilder.cs" />
<Compile Include="$(MSBuildThisFileDirectory)CodeBuilderExtensions.cs" />
Expand Down
20 changes: 20 additions & 0 deletions src/CodeGenHelpers/CompilerWarnings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace CodeGenHelpers
{
public class CompilerWarnings
{
/// <summary>
/// The field is never used
/// </summary>
public const string CS0169 = nameof(CS0169);

/// <summary>
/// The member is marked obsolete
/// </summary>
public const string CS0612 = nameof(CS0612);

/// <summary>
/// The member is marked obsolete with a message
/// </summary>
public const string CS0618 = nameof(CS0618);
}
}

0 comments on commit a80b741

Please # to comment.