forked from andrewabest/Conventional
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[andrewabestGH-87] Added new (Cecil based) convention to check that c…
…ode doesn't directly call Guid.NewGuid() A possible use-case is code written in a functional style (that wants to avoid non-deterministic behaviour)
- Loading branch information
eddie.stanley
committed
Jan 6, 2024
1 parent
754f500
commit 4239440
Showing
3 changed files
with
88 additions
and
7 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
21 changes: 21 additions & 0 deletions
21
src/Core/Conventional/Conventions/Cecil/MustNotUseGuidNewGuidConventionSpecification.cs
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System; | ||
using System.Linq.Expressions; | ||
using System.Reflection; | ||
|
||
namespace Conventional.Conventions.Cecil | ||
{ | ||
public class MustNotUseGuidNewGuidConventionSpecification : | ||
MustNotCallMethodConventionSpecification | ||
{ | ||
private static MethodInfo GetMethod() | ||
{ | ||
Expression<Func<Guid>> expr = () => Guid.NewGuid(); | ||
return ((MethodCallExpression)expr.Body).Method; | ||
} | ||
|
||
public MustNotUseGuidNewGuidConventionSpecification() | ||
: base(new[] { GetMethod() }) | ||
{ | ||
} | ||
} | ||
} |