diff --git a/Documentation/README.md b/Documentation/README.md index e8763e6..9b28a1e 100644 --- a/Documentation/README.md +++ b/Documentation/README.md @@ -67,5 +67,41 @@ When all tech debt for the project is materialized in single file - we can start It also helps to keep track of all tech debt in the project. Moreover, it is much easier to spot new technical debt during the code review. +## Enlisting dependencies of a class +To document dependencies of a specific class, we use the following tool: + +```csharp +[UsesVerify] +public class Relations +{ + [Theory] + [InlineData(typeof(Markdown))] + [InlineData(typeof(Markdown.Document))] + public async Task Generate(Type type) + { + // ARRANGE + var dependencies = Synergy.Documentation.Api.Dependencies.Of(type); + + // ACT + var publicApi = ApiDescription.GenerateFor(dependencies); + + // ASSERT + await Verifier.Verify(publicApi, "md") + .UseMethodName("of." + type.Name); + } +} +``` + +For sample code, please check: [Relations.cs](Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs) + +To see the results, please check: [Relations.of.Document.verified.md](Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md) + +[//]: # (TODO Write the documentation of Dependencies genaretor) + +## Generating markdown files from code - Docs as Code + +TBC + +[//]: # (TODO Write the documentation of Markdown class usage) diff --git a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs b/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs index 2cfe7f0..c123bd9 100644 --- a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs +++ b/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.cs @@ -14,8 +14,6 @@ public async Task Generate(Type type) // ARRANGE var dependencies = Synergy.Documentation.Api.Dependencies.Of(type); - - // TODO: Marcin Celej [from: Marcin Celej on: 26-12-2023]: Doe not work for Markdown.Document // ACT var publicApi = ApiDescription.GenerateFor(dependencies); diff --git a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md b/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md index 5f28270..1273195 100644 --- a/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md +++ b/Documentation/Synergy.Documentation.Tests/Architecture/Dependencies/Relations.of.Document.verified.md @@ -1 +1,11 @@ - \ No newline at end of file +## Synergy.Documentation.Markup.Markdown+Document (class) : IEnumerable, IEnumerable + - ctor() + - Append( + element: Markdown+IElement + ) : Markdown+Document + - Append( + newElements: IEnumerable + ) : Markdown+Document + - GetEnumerator() : IEnumerator + - ToString() : string + diff --git a/Documentation/Synergy.Documentation.Tests/Architecture/Public/Api.of.Synergy.Documentation.verified.md b/Documentation/Synergy.Documentation.Tests/Architecture/Public/Api.of.Synergy.Documentation.verified.md index e5713ab..8e2a8fb 100644 --- a/Documentation/Synergy.Documentation.Tests/Architecture/Public/Api.of.Synergy.Documentation.verified.md +++ b/Documentation/Synergy.Documentation.Tests/Architecture/Public/Api.of.Synergy.Documentation.verified.md @@ -42,9 +42,6 @@ - Dependencies.Of( root: Type ) : List - - DependsOn( - type: Type - ) : IEnumerable [IteratorStateMachine] ## Code.ClassReader (class) - ctor() diff --git a/Documentation/Synergy.Documentation/Api/Dependencies.cs b/Documentation/Synergy.Documentation/Api/Dependencies.cs index 798d76f..85e2909 100644 --- a/Documentation/Synergy.Documentation/Api/Dependencies.cs +++ b/Documentation/Synergy.Documentation/Api/Dependencies.cs @@ -8,49 +8,63 @@ public class Dependencies { public static List Of(Type root) { - return new Dependencies().DependsOn(root).ToList(); + return new Dependencies().DependenciesOf(root) + .ToList(); } private readonly List visited = new(100); - public Dependencies() + + private IEnumerable DependenciesOf(Type type) { + return this.DependenciesOf(type, 0); } - public IEnumerable DependsOn(Type type) + private IEnumerable DependenciesOf(Type type, int level) { var underlyingType = Nullable.GetUnderlyingType(type); if (underlyingType != null) type = underlyingType; - + if (type.IsPrimitive) yield break; if (type.In(typeof(string), typeof(Guid), typeof(DateTime), typeof(decimal))) yield break; + if (level == 0) + { + this.visited.Add(type); + yield return type; + } + if (type.IsArray) + { type = type.GetElementType(); + } else if (type.IsAssignableTo(typeof(IEnumerable))) { - if ( type.GetGenericArguments().Length == 0) + if (type.GetGenericArguments().Length == 0) yield break; - - type = type.GetGenericArguments().First(); + + type = type.GetGenericArguments() + .First(); } - + if (type.Namespace.StartsWith("System.")) yield break; - - if (this.visited.Contains(type)) + + if (this.visited.Contains(type) && level > 0) yield break; - this.visited.Add(type); - - yield return type; - + if (this.visited.Contains(type) == false) + { + this.visited.Add(type); + yield return type; + } + foreach (var property in this.GetPropertiesOf(type)) { - foreach (var dependency in this.DependsOn(property.PropertyType)) + foreach (var dependency in this.DependenciesOf(property.PropertyType)) { yield return dependency; }