Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<Configurations>Debug;Release;DebugGenerator</Configurations>
<SourceGenerator_EnableLogging>True</SourceGenerator_EnableLogging>
Expand All @@ -10,11 +10,7 @@
<SourceGenerator_IntellisenseFix>True</SourceGenerator_IntellisenseFix>
</PropertyGroup>
<ItemGroup>
<ProjectReference
Include="..\DotnetAutomaticInterface\DotnetAutomaticInterface.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false"
/>
<ProjectReference Include="..\DotnetAutomaticInterface\DotnetAutomaticInterface.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" />
</ItemGroup>
<ItemGroup>
<Folder Include="logs" />
Expand Down
77 changes: 77 additions & 0 deletions AutomaticInterface/AutomaticInterfaceExample/TestDocComments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using System;
using DotnetAutomaticInterface;

namespace AutomaticInterfaceExample;

public class Class1;

public class Class2;

/// <summary>
/// Debug utility to verify in IDE that doc comments are correctly rendered for the interface!
/// </summary>
/// <param name="clsParam">param</param>
[GenerateAutomaticInterface]
public class TestDocComments((Class1, Class2) clsParam) : ITestDocComments
{
private readonly (Class1, Class2) _clsParam = clsParam;

/// <summary>
/// Some Prop comment ...
/// </summary>
public bool SomeProp { get; set; }

/// <summary>
/// Some Comment..
/// </summary>
/// <param name="param">This is the param</param>
public void Method((Class1, Class2) param) { }

/// <summary>
/// Some Comment 2..
/// </summary>
/// <param name="timespan">param</param>
public void Method2((DateTime? from, DateTime? to) timespan) { }

/// <summary>
/// Some in comment...
/// </summary>
/// <param name="b"></param>
public void MethodIn(in bool b) { }

/// <summary>
/// Some params comment...
/// </summary>
/// <param name="a"></param>
public void MethodParams(params int[] a) { }

/// <summary>
/// Some Comment 3...
/// <see
/// cref="SomeProp" />
/// <see
/// cref="Method(ValueTuple{Class1, Class2})" />
/// <see
/// cref="Method2(ValueTuple{DateTime?, DateTime?})" />
/// </summary>
/// <param name="param">param</param>
/// <returns>Result</returns>
public bool Method3(Class1 param)
{
return true;
}
}

class SomeOtherClass
{
public static void Method(ITestDocComments param)
{
param.Method((new Class1(), new Class2()));
param.Method2((new DateTime(), new DateTime()));
param.Method3(new Class1());
var boolean = true;
param.MethodIn(in boolean);
param.MethodParams(1, 2);
param.SomeProp = true;
}
}
23 changes: 20 additions & 3 deletions AutomaticInterface/DotnetAutomaticInterface/Builder.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand All @@ -10,8 +9,25 @@ namespace DotnetAutomaticInterface;

public static class Builder
{
private static string InheritDoc(ISymbol source) =>
$"/// <inheritdoc cref=\"{source.ToDisplayString().Replace('<', '{').Replace('>', '}').Replace("params ", "")}\" />"; // we use inherit doc because that should be able to fetch documentation from base classes.
/// <summary>
/// Generates inheritdoc with canonical cref reference declaration.
/// </summary>
/// <param name="source">The symbol to annotate</param>
/// <returns>
/// <code>
/// /// &lt;inheritdoc cref="SomeSymbol" /&gt;
/// </code>
/// </returns>
private static string InheritDoc(ISymbol source)
{
var declarationId = DocumentationCommentId.CreateDeclarationId(source);
if (!string.IsNullOrWhiteSpace(declarationId))
return $"/// <inheritdoc cref=\"{declarationId}\" />";

// old probably hacky fallback ...
// we use inherit doc because that should be able to fetch documentation from base classes.
return $"/// <inheritdoc cref=\"{source.ToDisplayString().Replace('<', '{').Replace('>', '}').Replace("params ", "")}\" />";
}

private static readonly SymbolDisplayFormat FullyQualifiedDisplayFormat = new(
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
Expand Down Expand Up @@ -206,6 +222,7 @@ bool nullableContextEnabled
.Visit(param.DeclaringSyntaxReferences.First().GetSyntax())
.ToFullString();
}

return param.ToDisplayString(FullyQualifiedDisplayFormat);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.SomeProperty" />
/// <inheritdoc cref="P:AutomaticInterfaceExample.DemoClass.SomeProperty" />
global::AutomaticInterfaceExample.EnumWithByteType SomeProperty { get; set; }

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)~AutomaticInterfaceExample.EnumWithByteType" />
global::AutomaticInterfaceExample.EnumWithByteType MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.MethodWithDefaultParameter(AutomaticInterfaceExample.EnumWithByteType)" />
void MethodWithDefaultParameter(global::AutomaticInterfaceExample.EnumWithByteType a = global::AutomaticInterfaceExample.EnumWithByteType.B);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.ShapeChanged" />
/// <inheritdoc cref="E:AutomaticInterfaceExample.DemoClass.ShapeChanged" />
event global::System.EventHandler ShapeChanged;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.ShapeChangedNullable" />
/// <inheritdoc cref="E:AutomaticInterfaceExample.DemoClass.ShapeChangedNullable" />
event global::System.EventHandler? ShapeChangedNullable;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.ShapeChangedNullable" />
/// <inheritdoc cref="E:AutomaticInterfaceExample.DemoClass.ShapeChangedNullable" />
event global::System.EventHandler<string?> ShapeChangedNullable;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AnEvent" />
/// <inheritdoc cref="E:AutomaticInterfaceExample.DemoClass.AnEvent" />
event global::System.EventHandler AnEvent;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AnEvent" />
/// <inheritdoc cref="E:AutomaticInterfaceExample.DemoClass.AnEvent" />
event global::System.EventHandler AnEvent;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello(string)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.Hello(System.String)~System.String" />
string Hello(string x);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello(string)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.Hello(System.String)~System.String" />
string Hello(string x);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello()" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.Hello~System.String" />
string Hello();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello()" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.Hello~System.Threading.Tasks.Task{System.String}" />
global::System.Threading.Tasks.Task<string> Hello();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello(string, int, double)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.Hello(System.String,System.Int32,System.Double)~System.String" />
string Hello(string x, int y, double z);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello(System.Threading.Tasks.Task{string})" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.Hello(System.Threading.Tasks.Task{System.String})~System.String" />
string Hello(global::System.Threading.Tasks.Task<string> x);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.Hello(string)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.Hello(System.String)~System.String" />
string Hello(string x);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.GetFinalDocumentsByIDFails(string, string, bool, bool?, System.Threading.CancellationToken)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.GetFinalDocumentsByIDFails(System.String,System.String,System.Boolean,System.Nullable{System.Boolean},System.Threading.CancellationToken)~System.Threading.Tasks.Task{System.IO.Stream}" />
global::System.Threading.Tasks.Task<global::System.IO.Stream?> GetFinalDocumentsByIDFails(string agreementID, string docType, bool amt = false, bool? attachSupportingDocuments = true, global::System.Threading.CancellationToken cancellationToken = default(global::System.Threading.CancellationToken));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AMethod(string, string)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AMethod(System.String,System.String)~System.String" />
string AMethod(string x, string y);

/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AMethod(string, string, string)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AMethod(System.String,System.String,System.String)~System.String" />
string AMethod(string x, string y, string crash);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.CMethod{T, T1, T2, T3, T4, T5}(string, string)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.CMethod``6(System.String,System.String)~System.String" />
string CMethod<T, T1, T2, T3, T4, T5>(string x, string y) where T : class where T1 : struct where T3 : global::AutomaticInterfaceExample.DemoClass where T4 : IDemoClass where T5 : new();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AMethod(Func{Task{int}})" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AMethod(Func{Task{System.Int32}})" />
void AMethod(Func<Task<int>> getValue);

/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AMethod(Func{Task{float}})" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AMethod(Func{Task{System.Single}})" />
void AMethod(Func<Task<float>> getValue);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AMethod(Func{Task{AutomaticInterfaceExample.Types1.Model}})" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AMethod(Func{Task{AutomaticInterfaceExample.Types1.Model}})" />
void AMethod(Func<Task<global::AutomaticInterfaceExample.Types1.Model>> getValue);

/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AMethod(Func{Task{AutomaticInterfaceExample.Types2.Model}})" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AMethod(Func{Task{AutomaticInterfaceExample.Types2.Model}})" />
void AMethod(Func<Task<global::AutomaticInterfaceExample.Types2.Model>> getValue);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AddFilter{T}(IQueryable{T})" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AddFilter``1(IQueryable{``0})~IQueryable{``0}" />
IQueryable<T> AddFilter<T>(IQueryable<T> qry) where T : notnull;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AMethod(in int)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AMethod(System.Int32@)" />
void AMethod(in int someOutParameter);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AMethod(out int)" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AMethod(System.Int32@)" />
void AMethod(out int someOutParameter);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AutomaticInterfaceExample
[global::System.CodeDom.Compiler.GeneratedCode("DotnetAutomaticInterface", "")]
public partial interface IDemoClass
{
/// <inheritdoc cref="AutomaticInterfaceExample.DemoClass.AMethod()" />
/// <inheritdoc cref="M:AutomaticInterfaceExample.DemoClass.AMethod~System.Boolean" />
bool AMethod();

}
Expand Down
Loading