TypeElementExtensions Class
Provides extension methods on collections of TypeElement.
public static class TypeElementExtensionsMethods
| Name | Description |
|---|---|
| SliceByNamespace(IEnumerable<TypeElement>, string) | Groups types into slices by namespace, such as the modules of an application, to check the dependencies between the slices. |
SliceByNamespace(IEnumerable<TypeElement>, string)
TypeElementExtensions.csGroups types into slices by namespace, such as the modules of an application, to check the dependencies between the slices.
public static IReadOnlyList<IGrouping<string, TypeElement>> SliceByNamespace(this IEnumerable<TypeElement> types, string pattern)Parameters
typesIEnumerable<TypeElement>- The types to group.
patternstring- A namespace pattern with one
{slice}segment, whose value names the slice:MyApp.Modules.{slice}putsMyApp.Modules.OrdersandMyApp.Modules.Orders.Datain the sliceOrders. A*segment matches any segment. The types whose namespace does not match the pattern are in no slice.
Returns
IReadOnlyList<IGrouping<string, TypeElement>> The slices, sorted by name, each with its types in the order of types.
Exceptions
ArgumentException- The pattern does not have exactly one
{slice}segment.
Example
var architecture = ArchitectureModel.FromAssemblyContaining<Order>();
var modules = architecture.Types.SliceByNamespace("SampleApp.Modules.{slice}");
var exception = Assert.Throws<AssertionException>(() => Assert.Architecture.DoesNotHaveCycles(modules));
Assert.StartsWith("""
Assert.Architecture.DoesNotHaveCycles() assertion failed: 1 cycle between slices.
Slices expression: modules
- Billing -> Shipping -> Billing
SampleApp.Modules.Billing.Invoice.Shipment has a property of type SampleApp.Modules.Shipping.Shipment
""".ReplaceLineEndings("\n"), exception.Message);