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 convention to check that an assembly is …
…included (by name) in a haystack set of assemblies This can be used to ensure a list of assemblies (e.g. those containing "production code") is kept up-to-date *so that you can apply conventions to the types in those assemblies*.
- Loading branch information
eddie.stanley
committed
Jan 6, 2024
1 parent
4239440
commit 4a96fd6
Showing
3 changed files
with
85 additions
and
1 deletion.
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
36 changes: 36 additions & 0 deletions
36
...entional/Conventions/Assemblies/MustBeIncludedInSetOfAssembliesConventionSpecification.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,36 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Reflection; | ||
using System.Xml.Linq; | ||
|
||
namespace Conventional.Conventions.Assemblies | ||
{ | ||
public class MustBeIncludedInSetOfAssembliesConventionSpecification : AssemblyConventionSpecification | ||
{ | ||
private readonly ISet<string> _assemblyNames; | ||
private readonly string _assemblySetName; | ||
|
||
public MustBeIncludedInSetOfAssembliesConventionSpecification(IEnumerable<Assembly> assemblyNames, string assemblySetName) | ||
{ | ||
_assemblyNames = new HashSet<string>(assemblyNames.Select(assembly => assembly.GetName().Name)); | ||
_assemblySetName = assemblySetName; | ||
} | ||
|
||
protected override ConventionResult IsSatisfiedByLegacyCsprojFormat(string assemblyName, XDocument projectDocument) | ||
{ | ||
return IsSatisfiedBy(assemblyName, projectDocument); | ||
} | ||
|
||
protected override ConventionResult IsSatisfiedBy(string assemblyName, XDocument projectDocument) | ||
{ | ||
if (_assemblyNames.Contains(assemblyName)) | ||
{ | ||
return ConventionResult.Satisfied(assemblyName); | ||
} | ||
|
||
return ConventionResult.NotSatisfied(assemblyName, string.Format(FailureMessage, assemblyName)); | ||
} | ||
|
||
protected override string FailureMessage => "{0} is not included in " + _assemblySetName; | ||
} | ||
} |