Skip to content

Commit 719d03f

Browse files
committed
import initial codebase
1 parent e8fbd90 commit 719d03f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+2629
-1
lines changed

.editorconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[*.{cs,vb}]
2+
3+
# IDE0130: Namespace does not match folder structure
4+
dotnet_diagnostic.IDE0130.severity = none
5+
6+
# IDE0290: Use primary constructor
7+
dotnet_diagnostic.IDE0290.severity = none

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "nuget" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"

.github/workflows/Publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Release
2+
3+
on:
4+
repository_dispatch:
5+
push:
6+
tags:
7+
- "xdoc-v[0-9]+.[0-9]+.[0-9]+*"
8+
9+
env:
10+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
11+
NUGET_APIKEY: ${{ secrets.NUGET_APIKEY}}
12+
13+
jobs:
14+
15+
Release:
16+
name: Release
17+
runs-on: ubuntu-latest
18+
steps:
19+
20+
- name: Checkout
21+
uses: actions/checkout@v2
22+
23+
- name: Setup dotnet
24+
uses: actions/setup-dotnet@v4
25+
with:
26+
dotnet-version: '9.x'
27+
28+
- name: Verify commit
29+
run: |
30+
git fetch --no-tags --prune --depth=1 origin +refs/heads/*:refs/remotes/origin/*
31+
git branch --remote --contains | grep origin/main
32+
33+
- name: Set version
34+
run: echo "VERSION=${GITHUB_REF/refs\/tags\/xdoc-v/}" >> $GITHUB_ENV
35+
36+
- name: Build
37+
run: |
38+
dotnet build XDoc.Net.sln --configuration Release /p:Version=${VERSION}
39+
dotnet pack XDoc.Net.sln --configuration Release /p:Version=${VERSION} --no-build --output .
40+
41+
- name: Push
42+
run: |
43+
dotnet nuget push BitzArt.XDoc.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY}
44+
dotnet nuget push BitzArt.XDoc.PlainText.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY}
45+
dotnet nuget push BitzArt.XDoc.EntityFrameworkCore.${VERSION}.nupkg --source https://api.nuget.org/v3/index.json --api-key ${NUGET_APIKEY}
46+

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,3 +398,5 @@ FodyWeavers.xsd
398398

399399
# JetBrains Rider
400400
*.sln.iml
401+
402+
.idea/

README.md

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,101 @@
1-
# xdoc
1+
# xdoc.net
2+
3+
A lightweight and efficient tool for parsing, and managing C# XML documentation comments.
4+
5+
6+
### BitzArt.XDoc
7+
8+
BitzArt.XDoc is a lightweight .NET library for parsing and accessing XML documentation comments from your C# code. It provides an intuitive API to retrieve documentation for:
9+
* Types/classes
10+
* Properties
11+
* Methods
12+
* Fields
13+
14+
15+
```csharp
16+
17+
using BitzArt.XDoc;
18+
...
19+
20+
var xdoc = new XDoc();
21+
22+
var typeDocs = xdoc.Get(typeof(MyType));
23+
var propertyDocs = xDoc.Get(typeof(MyType).GetProperty(nameof(MyType.PropertyOne)));
24+
```
25+
26+
### BitzArt.XDoc.PlainText
27+
28+
BitzArt.XDoc.PlainText is an extension package for BitzArt.XDoc that enables rendering XML documentation
29+
comments into plain text.
30+
31+
```csharp
32+
33+
using BitzArt.XDoc;
34+
using Xdoc.Renderer.PlaintText;
35+
36+
...
37+
38+
var xdoc = new XDoc();
39+
40+
var typeDescrption = xDoc.Get(typeof(MyType)).ToPlainText();
41+
var propertyDescrption = xDoc.Get(typeof(MyType).GetProperty(nameof(MyType.PropertyOne))).ToPlainText();
42+
43+
```
44+
45+
46+
### BitzArt.XDoc.EntityFrameworkCore
47+
48+
#### Features:
49+
50+
BitzArt.XDoc.EntityFrameworkCore is an extension library that bridges XML documentation comments from C#
51+
code to Entity Framework Core database objects.
52+
53+
Example 1: Configure comments for all entities in your DbContext
54+
55+
```csharp
56+
using BitzArt.XDoc;
57+
using Xdoc.Renderer.PlaintText;
58+
using BitzArt.XDoc.EntityFrameworkCore
59+
...
60+
61+
services.AddScoped<EntitiesCommentConfigurator>();
62+
63+
...
64+
65+
public class MyDbContext : DbContext
66+
{
67+
private readonly EntitiesCommentConfigurator _commentConfigurator;
68+
69+
public MyDbContext(DbContextOptions options, EntitiesCommentConfigurator commentConfigurator) : base(options)
70+
{
71+
_commentConfigurator = commentConfigurator;
72+
}
73+
74+
protected override void OnModelCreating(ModelBuilder modelBuilder)
75+
{
76+
base.OnModelCreating(modelBuilder);
77+
78+
// Configure comments for all entities
79+
_commentConfigurator.ConfigureComments(modelBuilder);
80+
}
81+
}
82+
```
83+
84+
85+
Example 2: Configure comments for specific properties using Fluent API
86+
87+
88+
```csharp
89+
using BitzArt.XDoc;
90+
using Xdoc.Renderer.PlaintText;
91+
using BitzArt.XDoc.EntityFrameworkCore
92+
93+
...
94+
95+
protected override void OnModelCreating(ModelBuilder modelBuilder)
96+
{
97+
modelBuilder.Entity<Customer>()
98+
.Property(c => c.Name)
99+
.MapPropertyComment<string, Customer>(c => c.Name);
100+
}
101+
```

XDoc.Net.sln

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.12.35527.113
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{DE8DA5D7-65DB-4FE8-8CF9-52CEB9CE6648}"
7+
EndProject
8+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{616D63B3-7EF0-40FB-A404-33A221F65577}"
9+
EndProject
10+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc", "src\BitzArt.XDoc\BitzArt.XDoc.csproj", "{051F3A64-78F8-4055-9785-5D5A3C489832}"
11+
EndProject
12+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.Tests", "tests\BitzArt.XDoc.Tests\BitzArt.XDoc.Tests.csproj", "{D6F5A728-53AD-49F9-8BA0-1E72D0AF6A93}"
13+
EndProject
14+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.PlainText", "src\Render\BitzArt.XDoc.PlainText\BitzArt.XDoc.PlainText.csproj", "{95283F56-EFD3-4B32-AE26-4E486D186127}"
15+
EndProject
16+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.PlaintText.Tests", "tests\Render\BitzArt.XDoc.PlaintText.Tests\BitzArt.XDoc.PlaintText.Tests.csproj", "{4F4720A9-8DD2-4DFD-B217-A0FAFC6F60D0}"
17+
EndProject
18+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sln", "sln", "{4DF4BD72-775C-4D08-8192-DAD007669051}"
19+
ProjectSection(SolutionItems) = preProject
20+
.editorconfig = .editorconfig
21+
EndProjectSection
22+
EndProject
23+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Render", "Render", "{7678586D-A35F-4155-9651-19E9F5770607}"
24+
EndProject
25+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Render", "Render", "{E34A2AB7-3E63-488C-85FC-72BB747ACD6F}"
26+
EndProject
27+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MultiAssemblyTests", "MultiAssemblyTests", "{401AF0D6-F0A9-43CE-9CB6-B3BFC69FFE31}"
28+
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAssembly.A", "tests\MultiAssemblyTests\TestAssembly.A\TestAssembly.A.csproj", "{4398E200-26F9-4184-A943-47738FF5EB4E}"
30+
EndProject
31+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestAssembly.B", "tests\MultiAssemblyTests\TestAssembly.B\TestAssembly.B.csproj", "{152D5D7F-EDF8-489C-B2BE-F22E5F63263F}"
32+
EndProject
33+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitzArt.XDoc.EntityFrameworkCore", "src\BitzArt.XDoc.EntityFrameworkCore\BitzArt.XDoc.EntityFrameworkCore.csproj", "{69E03C89-EA2B-4C47-BF61-70C5F9E56550}"
34+
EndProject
35+
Global
36+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
37+
Debug|Any CPU = Debug|Any CPU
38+
Release|Any CPU = Release|Any CPU
39+
EndGlobalSection
40+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
41+
{051F3A64-78F8-4055-9785-5D5A3C489832}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{051F3A64-78F8-4055-9785-5D5A3C489832}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{051F3A64-78F8-4055-9785-5D5A3C489832}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{051F3A64-78F8-4055-9785-5D5A3C489832}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{D6F5A728-53AD-49F9-8BA0-1E72D0AF6A93}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{D6F5A728-53AD-49F9-8BA0-1E72D0AF6A93}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{D6F5A728-53AD-49F9-8BA0-1E72D0AF6A93}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{D6F5A728-53AD-49F9-8BA0-1E72D0AF6A93}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{95283F56-EFD3-4B32-AE26-4E486D186127}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{95283F56-EFD3-4B32-AE26-4E486D186127}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{95283F56-EFD3-4B32-AE26-4E486D186127}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{95283F56-EFD3-4B32-AE26-4E486D186127}.Release|Any CPU.Build.0 = Release|Any CPU
53+
{4F4720A9-8DD2-4DFD-B217-A0FAFC6F60D0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{4F4720A9-8DD2-4DFD-B217-A0FAFC6F60D0}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{4F4720A9-8DD2-4DFD-B217-A0FAFC6F60D0}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{4F4720A9-8DD2-4DFD-B217-A0FAFC6F60D0}.Release|Any CPU.Build.0 = Release|Any CPU
57+
{4398E200-26F9-4184-A943-47738FF5EB4E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
58+
{4398E200-26F9-4184-A943-47738FF5EB4E}.Debug|Any CPU.Build.0 = Debug|Any CPU
59+
{4398E200-26F9-4184-A943-47738FF5EB4E}.Release|Any CPU.ActiveCfg = Release|Any CPU
60+
{4398E200-26F9-4184-A943-47738FF5EB4E}.Release|Any CPU.Build.0 = Release|Any CPU
61+
{152D5D7F-EDF8-489C-B2BE-F22E5F63263F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
62+
{152D5D7F-EDF8-489C-B2BE-F22E5F63263F}.Debug|Any CPU.Build.0 = Debug|Any CPU
63+
{152D5D7F-EDF8-489C-B2BE-F22E5F63263F}.Release|Any CPU.ActiveCfg = Release|Any CPU
64+
{152D5D7F-EDF8-489C-B2BE-F22E5F63263F}.Release|Any CPU.Build.0 = Release|Any CPU
65+
{69E03C89-EA2B-4C47-BF61-70C5F9E56550}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
66+
{69E03C89-EA2B-4C47-BF61-70C5F9E56550}.Debug|Any CPU.Build.0 = Debug|Any CPU
67+
{69E03C89-EA2B-4C47-BF61-70C5F9E56550}.Release|Any CPU.ActiveCfg = Release|Any CPU
68+
{69E03C89-EA2B-4C47-BF61-70C5F9E56550}.Release|Any CPU.Build.0 = Release|Any CPU
69+
EndGlobalSection
70+
GlobalSection(SolutionProperties) = preSolution
71+
HideSolutionNode = FALSE
72+
EndGlobalSection
73+
GlobalSection(NestedProjects) = preSolution
74+
{051F3A64-78F8-4055-9785-5D5A3C489832} = {DE8DA5D7-65DB-4FE8-8CF9-52CEB9CE6648}
75+
{D6F5A728-53AD-49F9-8BA0-1E72D0AF6A93} = {616D63B3-7EF0-40FB-A404-33A221F65577}
76+
{95283F56-EFD3-4B32-AE26-4E486D186127} = {7678586D-A35F-4155-9651-19E9F5770607}
77+
{4F4720A9-8DD2-4DFD-B217-A0FAFC6F60D0} = {E34A2AB7-3E63-488C-85FC-72BB747ACD6F}
78+
{7678586D-A35F-4155-9651-19E9F5770607} = {DE8DA5D7-65DB-4FE8-8CF9-52CEB9CE6648}
79+
{E34A2AB7-3E63-488C-85FC-72BB747ACD6F} = {616D63B3-7EF0-40FB-A404-33A221F65577}
80+
{401AF0D6-F0A9-43CE-9CB6-B3BFC69FFE31} = {616D63B3-7EF0-40FB-A404-33A221F65577}
81+
{4398E200-26F9-4184-A943-47738FF5EB4E} = {401AF0D6-F0A9-43CE-9CB6-B3BFC69FFE31}
82+
{152D5D7F-EDF8-489C-B2BE-F22E5F63263F} = {401AF0D6-F0A9-43CE-9CB6-B3BFC69FFE31}
83+
{69E03C89-EA2B-4C47-BF61-70C5F9E56550} = {DE8DA5D7-65DB-4FE8-8CF9-52CEB9CE6648}
84+
EndGlobalSection
85+
EndGlobal

assets/xdoc-logo.png

77.4 KB
Loading
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<GenerateDocumentationFile>true</GenerateDocumentationFile>
8+
<RootNamespace>BitzArt.XDoc.EntityFrameworkCore</RootNamespace>
9+
10+
<PackageId>BitzArt.XDoc.EntityFrameworkCore</PackageId>
11+
<Authors>BitzArt</Authors>
12+
<Description>Extension library that bridges XML documentation comments from C# code to Entity Framework Core database objects.</Description>
13+
<PackageLicenseExpression>MIT</PackageLicenseExpression>
14+
<RepositoryType>git</RepositoryType>
15+
<RepositoryUrl>https://github.com/BitzArt/xdoc</RepositoryUrl>
16+
<PackageProjectUrl>https://github.com/BitzArt/xdoc</PackageProjectUrl>
17+
<PackageReadmeFile>README.md</PackageReadmeFile>
18+
<PackageIcon>xdoc-logo.png</PackageIcon>
19+
</PropertyGroup>
20+
21+
<ItemGroup>
22+
<None Include="..\..\assets\xdoc-logo.png" Pack="True" Visible="false" PackagePath="\" />
23+
<None Include="..\..\README.md" Pack="True" Visible="false" PackagePath="\" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<PackageReference Include="JetBrains.Annotations" Version="2024.3.0" PrivateAssets="All"/>
28+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.2"/>
29+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.2"/>
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<ProjectReference Include="..\BitzArt.XDoc\BitzArt.XDoc.csproj"/>
34+
<ProjectReference Include="..\Render\BitzArt.XDoc.PlainText\BitzArt.XDoc.PlainText.csproj"/>
35+
</ItemGroup>
36+
37+
</Project>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
using BitzArt.XDoc.PlainText;
2+
using JetBrains.Annotations;
3+
using Microsoft.EntityFrameworkCore;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace BitzArt.XDoc.EntityFrameworkCore;
7+
8+
/// <summary>
9+
/// Configures XML documentation comments for Entity Framework Core entities and their properties.
10+
/// </summary>
11+
[PublicAPI]
12+
public class EntitiesCommentConfigurator
13+
{
14+
private readonly ILogger _logger;
15+
private readonly XDoc _xDoc;
16+
17+
/// <summary>
18+
/// Default constructor.
19+
/// </summary>
20+
public EntitiesCommentConfigurator(XDoc xDoc, ILogger<EntitiesCommentConfigurator> logger)
21+
{
22+
_logger = logger;
23+
_xDoc = xDoc;
24+
}
25+
26+
/// <summary>
27+
/// Configure comments for entities and properties.
28+
/// </summary>
29+
/// <param name="modelBuilder"></param>
30+
public void ConfigureComments(ModelBuilder modelBuilder)
31+
{
32+
var entityTypes = modelBuilder.Model.GetEntityTypes();
33+
34+
foreach (var entityType in entityTypes)
35+
{
36+
var entityComment = _xDoc.Get(entityType.ClrType).ToPlainText();
37+
38+
// For owned entities, we don't set the comment on the entity itself
39+
// But we will set the comment on the properties
40+
41+
var isOwned = entityType.IsOwned();
42+
var tableName = entityType.GetTableName();
43+
44+
if (!isOwned && tableName is not null)
45+
{
46+
entityType.SetComment(entityComment);
47+
}
48+
49+
var properties = entityType.GetProperties();
50+
51+
foreach (var property in properties)
52+
{
53+
var isShadowProperty = property.IsShadowProperty();
54+
55+
if (isShadowProperty)
56+
{
57+
_logger.LogInformation($"Skipping shadow property [Name: {property.Name}]");
58+
59+
continue;
60+
}
61+
62+
var propertyInfo = entityType.ClrType.GetProperty(property.Name);
63+
64+
if (propertyInfo == null)
65+
{
66+
return;
67+
}
68+
69+
var propertyComment = _xDoc.Get(propertyInfo).ToPlainText();
70+
71+
property.SetComment(propertyComment);
72+
}
73+
}
74+
}
75+
}

0 commit comments

Comments
 (0)