-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
assign obsoletion of a binding method on creation instead of on usage…
… of BindingMatch
- Loading branch information
Showing
9 changed files
with
38 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,34 @@ | ||
using System; | ||
using System.Linq; | ||
using TechTalk.SpecFlow.Bindings.Reflection; | ||
|
||
namespace TechTalk.SpecFlow.Bindings | ||
{ | ||
public class BindingObsoletion | ||
#nullable enable | ||
public readonly struct BindingObsoletion | ||
{ | ||
private const string defaultObsoletionMessage = "it is marked with ObsoleteAttribute but no custom message was provided."; | ||
private const string DefaultObsoletionMessage = "it is marked with ObsoleteAttribute but no custom message was provided."; | ||
|
||
private string message; | ||
private string methodName; | ||
internal static readonly BindingObsoletion NotObsolete = new BindingObsoletion(); | ||
|
||
public BindingObsoletion(IStepDefinitionBinding stepBinding) | ||
private readonly string? message; | ||
private readonly string? methodName; | ||
|
||
public bool IsObsolete => message is not null; | ||
|
||
public BindingObsoletion(IBindingMethod methodBinding, ObsoleteAttribute? attribute) | ||
{ | ||
ObsoleteAttribute possibleObsoletionAttribute; | ||
try | ||
if (attribute is not null) | ||
{ | ||
possibleObsoletionAttribute = stepBinding?.Method.AssertMethodInfo() | ||
.GetCustomAttributes(false).OfType<ObsoleteAttribute>() | ||
.FirstOrDefault(); | ||
message = attribute.Message ?? DefaultObsoletionMessage; | ||
methodName = methodBinding.Name; | ||
} | ||
catch (Exception) | ||
{ | ||
possibleObsoletionAttribute = null; | ||
} | ||
|
||
if (possibleObsoletionAttribute == null) | ||
else | ||
{ | ||
IsObsolete = false; | ||
message = null; | ||
methodName = null; | ||
} | ||
else | ||
{ | ||
IsObsolete = true; | ||
message = possibleObsoletionAttribute.Message ?? defaultObsoletionMessage; | ||
methodName = stepBinding?.Method.Name; | ||
} | ||
} | ||
|
||
public bool IsObsolete { get; private set; } | ||
|
||
public string Message => IsObsolete ? $"The step {methodName} is obsolete because {message}" : string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters