Skip to content

Commit

Permalink
Merge pull request cake-build#1012 from devlead/feature/cake-buildGH-974
Browse files Browse the repository at this point in the history


GH974: Supress obsolete warnings from generated code
  • Loading branch information
gep13 authored Jun 28, 2016
2 parents 88b264b + 68d56d7 commit ff508d3
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
public void Obsolete_ExplicitWarning_WithMessage()
{
Context.Log.Warning("Warning: The alias Obsolete_ExplicitWarning_WithMessage has been made obsolete. Please use Foo.Bar instead.");
#pragma warning disable 0618
Cake.Core.Tests.Data.MethodAliasGeneratorData.Obsolete_ExplicitWarning_WithMessage(Context);
#pragma warning restore 0618
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
public void Obsolete_ImplicitWarning_NoMessage()
{
Context.Log.Warning("Warning: The alias Obsolete_ImplicitWarning_NoMessage has been made obsolete.");
#pragma warning disable 0618
Cake.Core.Tests.Data.MethodAliasGeneratorData.Obsolete_ImplicitWarning_NoMessage(Context);
#pragma warning restore 0618
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
public void Obsolete_ImplicitWarning_WithMessage()
{
Context.Log.Warning("Warning: The alias Obsolete_ImplicitWarning_WithMessage has been made obsolete. Please use Foo.Bar instead.");
#pragma warning disable 0618
Cake.Core.Tests.Data.MethodAliasGeneratorData.Obsolete_ImplicitWarning_WithMessage(Context);
#pragma warning restore 0618
}
13 changes: 12 additions & 1 deletion src/Cake.Core/Scripting/CodeGen/MethodAliasGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ public static string Generate(MethodInfo method)

// Method is obsolete?
var obsolete = method.GetCustomAttribute<ObsoleteAttribute>();
if (obsolete != null)
var isObsolete = obsolete != null;
if (isObsolete)
{
var message = GetObsoleteMessage(method, obsolete);

Expand All @@ -79,6 +80,11 @@ public static string Generate(MethodInfo method)
" Context.Log.Warning(\"Warning: {0}\");", message));
}

if (isObsolete)
{
builder.AppendLine("#pragma warning disable 0618");
}

builder.Append(" ");

if (isFunction)
Expand All @@ -101,6 +107,11 @@ public static string Generate(MethodInfo method)
builder.Append(");");
builder.AppendLine();

if (isObsolete)
{
builder.AppendLine("#pragma warning restore 0618");
}

// End method.
builder.Append("}");
builder.AppendLine();
Expand Down

0 comments on commit ff508d3

Please sign in to comment.