Skip to content

Commit

Permalink
updated documentation comments (#16)
Browse files Browse the repository at this point in the history
This fixes #15 where type names of constructed generic types were causing warnings when documentation files are generated for a project
  • Loading branch information
IGood committed Oct 16, 2021
1 parent 8f32853 commit db0cc9e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 9 deletions.
1 change: 1 addition & 0 deletions Bpz.Test/Bpz.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<UseWPF>true</UseWPF>
<IsPackable>false</IsPackable>
<Nullable>enable</Nullable>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<ItemGroup>
Expand Down
9 changes: 8 additions & 1 deletion Bpz.Test/MyService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright © Ian Good

using System.Collections.Generic;
using System.Windows;

namespace Bpz.Test
Expand All @@ -10,7 +11,13 @@ public static partial class MyService

public static readonly RoutedEvent FooChangedEvent = GenAttached.FooChanged<RoutedPropertyChangedEventHandler<int>>(RoutingStrategy.Bubble);

public static readonly RoutedEvent BarChangedEvent = GenAttached.BarChanged<int>();
public static readonly RoutedEvent BarChangedEvent = GenAttached.BarChanged<List<float>>();

public static readonly RoutedEvent InspectedEvent = GenAttached<System.Windows.Controls.Canvas>.Inspected();

public static readonly RoutedEvent SomeToolTipEvent = GenAttached.SomeToolTip<System.Windows.Controls.ToolTipEventHandler>();

public static readonly RoutedEvent DataTransferEvent = GenAttached.DataTransfer<System.EventHandler<System.Windows.Data.DataTransferEventArgs>>();

private static readonly RoutedEvent SomethingPrivateHappenedEvent = GenAttached.SomethingPrivateHappened();
}
Expand Down
25 changes: 24 additions & 1 deletion Bpz.Test/MyServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,30 @@ public static IEnumerable<RoutedEventAssert.RoutedEventValues> MetadataTestCases
{
OwnerType = typeof(MyService),
Name = "BarChanged",
HandlerType = typeof(RoutedPropertyChangedEventHandler<int>),
HandlerType = typeof(RoutedPropertyChangedEventHandler<List<float>>),
IsAttached = true,
};

yield return new()
{
OwnerType = typeof(MyService),
Name = "Inspected",
AttachmentNarrowingType = typeof(System.Windows.Controls.Canvas),
};

yield return new()
{
OwnerType = typeof(MyService),
Name = "SomeToolTip",
HandlerType = typeof(System.Windows.Controls.ToolTipEventHandler),
IsAttached = true,
};

yield return new()
{
OwnerType = typeof(MyService),
Name = "DataTransfer",
HandlerType = typeof(System.EventHandler<System.Windows.Data.DataTransferEventArgs>),
IsAttached = true,
};

Expand Down
3 changes: 3 additions & 0 deletions Bpz.Test/Widget.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright © Ian Good

using System;
using System.Collections.Generic;
using System.Windows;

namespace Bpz.Test
Expand All @@ -19,6 +20,8 @@ public partial class Widget : DependencyObject
public static readonly DependencyProperty MyString2Property = Gen.MyString2(default(string?));
public static readonly DependencyProperty MyString3Property = Gen.MyString3("qwer");

public static readonly DependencyProperty MyDictionaryProperty = Gen.MyDictionary<Dictionary<int, List<string>>?>();

private static void MyString0PropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
((Widget)d).MyString0Changed?.Invoke(d, EventArgs.Empty);
Expand Down
8 changes: 8 additions & 0 deletions Bpz.Test/WidgetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public static IEnumerable<DependencyPropertyAssert.DependencyPropertyValues> Met
DefaultValue = "qwer",
};

yield return new()
{
OwnerType = typeof(Widget),
Name = "MyDictionary",
PropertyType = typeof(Dictionary<int, List<string>>),
DefaultValue = null,
};

yield return new()
{
OwnerType = typeof(Widget),
Expand Down
4 changes: 2 additions & 2 deletions boilerplatezero/Wpf/DependencyPropertyGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private void ApppendSource(GeneratorExecutionContext context, StringBuilder sour
{
generateThis.AttachmentNarrowingType = attachmentNarrowingType;
targetTypeName = attachmentNarrowingType.ToDisplayString();
moreDox = $@"<br/>This attached property is only for use with objects of type <see cref=""{GeneratorOps.ReplaceBrackets(targetTypeName)}""/>.";
moreDox = $@"<br/>This attached property is only for use with objects of type <typeparamref name=""__TTarget""/>.";
}
}
else
Expand Down Expand Up @@ -291,7 +291,7 @@ private void ApppendSource(GeneratorExecutionContext context, StringBuilder sour
private static partial class {genClassDecl}
{{
/// <summary>
/// Registers {what} named ""{propertyName}"" whose type is <see cref=""{GeneratorOps.ReplaceBrackets(generateThis.PropertyTypeName)}""/>.{moreDox}
/// Registers {what} named ""{propertyName}"" whose type is <typeparamref name=""__T""/>.{moreDox}
/// </summary>
public static {returnType} {propertyName}<__T>({parameters})
{{
Expand Down
14 changes: 11 additions & 3 deletions boilerplatezero/Wpf/RoutedEventGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,27 @@ private void ApppendSource(GeneratorExecutionContext context, StringBuilder sour
string eventName = generateThis.MethodNameNode.Identifier.ValueText;
string routedEventMemberName = generateThis.FieldSymbol.Name;

string eventHandlerTypeDoxString = $@"<see cref=""{this.rehTypeSymbol.ToDisplayString()}""/>";

// Try to get the generic type argument (if it exists, this will be the type of the event handler).
if (GeneratorOps.TryGetGenericTypeArgument(context, generateThis.MethodNameNode, out ITypeSymbol? genTypeArg))
{
// If the type is a multicast delegate, then use it;
// otherwise, use the type in a `RoutedPropertyChangedEventHandler<>`.
if (genTypeArg.BaseType?.Equals(this.mdTypeSymbol, SymbolEqualityComparer.Default) ?? false)
{
// Good to go!
// Good to go! Documentation can reference the generic type parameter.
eventHandlerTypeDoxString = @"<typeparamref name=""__T""/>";
}
else
{
// Example: Transform `double` into `RoutedPropertyChangedEventHandler<double>`.
genTypeArg = this.rpcehTypeSymbol.Construct(genTypeArg);

// Documentation will appear as something like...
// RoutedPropertyChangedEventHandler<T> of double
string rpcehT = GeneratorOps.ReplaceBrackets(this.rpcehTypeSymbol.ToDisplayString());
eventHandlerTypeDoxString = $@"<see cref=""{rpcehT}""/> of <typeparamref name=""__T""/>";
}
}

Expand All @@ -153,7 +161,7 @@ private void ApppendSource(GeneratorExecutionContext context, StringBuilder sour
generateThis.AttachmentNarrowingType = attachmentNarrowingType;
targetTypeName = attachmentNarrowingType.ToDisplayString();
callerExpression = "d";
moreDox = $@"<br/>This attached event is only for use with objects of type <see cref=""{GeneratorOps.ReplaceBrackets(targetTypeName)}""/>.";
moreDox = $@"<br/>This attached event is only for use with objects of type <typeparamref name=""__TTarget""/>.";
}
}
else
Expand Down Expand Up @@ -207,7 +215,7 @@ private void ApppendSource(GeneratorExecutionContext context, StringBuilder sour
private static partial class {genClassDecl}
{{
/// <summary>
/// Registers {what} named ""{eventName}"" whose handler type is <see cref=""{GeneratorOps.ReplaceBrackets(generateThis.EventHandlerTypeName)}""/>.{moreDox}
/// Registers {what} named ""{eventName}"" whose handler type is {eventHandlerTypeDoxString}.{moreDox}
/// </summary>
public static RoutedEvent {eventName}{maybeGeneric}(RoutingStrategy routingStrategy = RoutingStrategy.Direct)
{{
Expand Down
4 changes: 2 additions & 2 deletions boilerplatezero/boilerplatezero.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<DevelopmentDependency>true</DevelopmentDependency>
<IncludeBuildOutput>false</IncludeBuildOutput>
<PackageId>boilerplatezero</PackageId>
<Version>1.7.0</Version>
<Version>1.7.1</Version>
<Authors>IGood</Authors>
<Company />
<Copyright>Copyright (c) Ian Good</Copyright>
Expand All @@ -25,7 +25,7 @@ Included generators:
<PackageProjectUrl>https://github.com/IGood/boilerplatezero</PackageProjectUrl>
<RepositoryUrl>https://github.com/IGood/boilerplatezero.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>bpz,source generator,wpf,dependency properties, routed events</PackageTags>
<PackageTags>bpz,source generator,wpf,dependency properties,routed events</PackageTags>
<PackageIcon>bpz logo dark.png</PackageIcon>
</PropertyGroup>

Expand Down

0 comments on commit db0cc9e

Please sign in to comment.