Skip to content

Commit

Permalink
Improved XML comments in unions
Browse files Browse the repository at this point in the history
  • Loading branch information
PawelGerr committed Oct 25, 2024
1 parent 76ec0ab commit 3b64d2e
Show file tree
Hide file tree
Showing 3 changed files with 378 additions and 371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,10 @@ private void GenerateImplicitConversions()
_sb.Append(@"
/// <summary>
/// Implicit conversion from type <c>").AppendTypeMinimallyQualified(memberType).Append(@"</c>.
/// Implicit conversion from type ").AppendTypeForXmlComment(memberType).Append(@".
/// </summary>
/// <param name=""").Append(memberType.ArgumentName).Append(@""">Value to covert from.</param>
/// <returns>A new instance of <see cref=""").AppendTypeMinimallyQualified(_state).Append(@"""/> converted from <paramref name=""").Append(memberType.ArgumentName).Append(@"""/>.</returns>
/// <returns>A new instance of ").AppendTypeForXmlComment(_state).Append(@" converted from <paramref name=""").Append(memberType.ArgumentName).Append(@"""/>.</returns>
public static implicit operator ").AppendTypeFullyQualified(_state).Append("(").AppendTypeFullyQualified(memberType).Append(" ").AppendEscaped(memberType.ArgumentName).Append(@")
{
return new ").AppendTypeFullyQualified(_state).Append("(").AppendEscaped(memberType.ArgumentName).Append(@");
Expand All @@ -153,11 +153,11 @@ private void GenerateExplicitConversions()
_sb.Append(@"
/// <summary>
/// Implicit conversion to type <c>").AppendTypeMinimallyQualified(memberType).Append(@"</c>.
/// Implicit conversion to type ").AppendTypeForXmlComment(memberType).Append(@".
/// </summary>
/// <param name=""obj"">Object to covert.</param>
/// <returns>Inner value of type <c>").AppendTypeMinimallyQualified(memberType).Append(@"</c>.</returns>
/// <exception cref=""System.InvalidOperationException"">If the inner value is not a <c>").AppendTypeMinimallyQualified(memberType).Append(@"</c>.</exception>
/// <returns>Inner value of type ").AppendTypeForXmlComment(memberType).Append(@".</returns>
/// <exception cref=""System.InvalidOperationException"">If the inner value is not a ").AppendTypeForXmlComment(memberType).Append(@".</exception>
public static explicit operator ").AppendTypeFullyQualified(memberType).Append("(").AppendTypeFullyQualified(_state).Append(@" obj)
{
return obj.As").Append(memberType.Name).Append(@";
Expand All @@ -170,7 +170,7 @@ private void GenerateEqualityOperators()
_sb.Append(@"
/// <summary>
/// Compares two instances of <see cref=""").AppendTypeMinimallyQualified(_state).Append(@"""/>.
/// Compares two instances of ").AppendTypeForXmlComment(_state).Append(@".
/// </summary>
/// <param name=""obj"">Instance to compare.</param>
/// <param name=""other"">Another instance to compare.</param>
Expand All @@ -191,7 +191,7 @@ private void GenerateEqualityOperators()
}
/// <summary>
/// Compares two instances of <see cref=""").AppendTypeMinimallyQualified(_state).Append(@"""/>.
/// Compares two instances of ").AppendTypeForXmlComment(_state).Append(@".
/// </summary>
/// <param name=""obj"">Instance to compare.</param>
/// <param name=""other"">Another instance to compare.</param>
Expand Down Expand Up @@ -388,7 +388,7 @@ private void GenerateSwitchForAction(bool withContext, bool isPartially)
var memberType = _state.MemberTypes[i];

_sb.Append(@"
/// <param name=""").Append(memberType.ArgumentName).Append(@""">The action to execute if the current value is of type <c>").AppendTypeMinimallyQualified(memberType).Append("</c>.</param>");
/// <param name=""").Append(memberType.ArgumentName).Append(@""">The action to execute if the current value is of type ").AppendTypeForXmlComment(memberType).Append(".</param>");
}

if (!_state.IsReferenceType)
Expand Down Expand Up @@ -536,7 +536,7 @@ private void GenerateSwitchForFunc(bool withContext, bool isPartially)
var memberType = _state.MemberTypes[i];

_sb.Append(@"
/// <param name=""").Append(memberType.ArgumentName).Append(@""">The function to execute if the current value is of type <c>").AppendTypeMinimallyQualified(memberType).Append("</c>.</param>");
/// <param name=""").Append(memberType.ArgumentName).Append(@""">The function to execute if the current value is of type ").AppendTypeForXmlComment(memberType).Append(".</param>");
}

if (!_state.IsReferenceType)
Expand Down Expand Up @@ -679,7 +679,7 @@ private void GenerateMap(bool isPartially)
var memberType = _state.MemberTypes[i];

_sb.Append(@"
/// <param name=""").Append(memberType.ArgumentName).Append(@""">The instance to return if the current value is of type <c>").AppendTypeMinimallyQualified(memberType).Append("</c>.</param>");
/// <param name=""").Append(memberType.ArgumentName).Append(@""">The instance to return if the current value is of type ").AppendTypeForXmlComment(memberType).Append(".</param>");
}

if (!_state.IsReferenceType)
Expand Down Expand Up @@ -812,7 +812,7 @@ private void GenerateMemberTypeFieldsAndProps()
_sb.Append(@"
/// <summary>
/// Indication whether the current value is of type <c>").AppendTypeMinimallyQualified(memberType).Append(@"</c>.
/// Indication whether the current value is of type ").AppendTypeForXmlComment(memberType).Append(@".
/// </summary>
public bool Is").Append(memberType.Name).Append(" => this._valueIndex == ").Append(i + 1).Append(";");
}
Expand All @@ -823,9 +823,9 @@ private void GenerateMemberTypeFieldsAndProps()
_sb.Append(@"
/// <summary>
/// Gets the current value as <c>").AppendTypeMinimallyQualified(memberType).Append(@"</c>.
/// Gets the current value as ").AppendTypeForXmlComment(memberType).Append(@".
/// </summary>
/// <exception cref=""global::System.InvalidOperationException"">If the current value is not of type <c>").AppendTypeMinimallyQualified(memberType).Append(@"</c>.</exception>
/// <exception cref=""global::System.InvalidOperationException"">If the current value is not of type ").AppendTypeForXmlComment(memberType).Append(@".</exception>
public ").AppendTypeFullyQualified(memberType).Append(" As").Append(memberType.Name).Append(" => Is").Append(memberType.Name)
.Append(" ? this._").Append(memberType.ArgumentName).Append(memberType.IsReferenceType && memberType.NullableAnnotation != NullableAnnotation.Annotated ? "!" : null)
.Append(" : throw new global::System.InvalidOperationException($\"'{nameof(").AppendTypeFullyQualified(_state).Append(")}' is not of type '").AppendTypeMinimallyQualified(memberType).Append("'.\");");
Expand Down
Loading

0 comments on commit 3b64d2e

Please sign in to comment.