Skip to content

extension Refactoring Should Handle <param> and <typeparam> XML Comment Elements #81859

@JasonBock

Description

@JasonBock

Version Used:

Steps to Reproduce:

  1. Create this code:
/// <summary>
/// Provides extension methods for <see cref="IEnumerable{T}"/>-based objects.
/// </summary>
public static class IDictionaryExtensions
{
	/// <summary>
	/// Adds key-value pairs to <paramref name="self"/>.
	/// </summary>
	/// <typeparam name="TKey">The type of the key.</typeparam>
	/// <typeparam name="TValue">The type of the value.</typeparam>
	/// <param name="self">The dictionary to add pairs to.</param>
	/// <param name="pairs">The pairs to add to <paramref name="self"/>.</param>
	/// <exception cref="ArgumentNullException">Thrown if <paramref name="self"/> or <paramref name="pairs"/> is <see langword="null" />.</exception>
	public static void AddPairs<TKey, TValue>(this IDictionary<TKey, TValue> self, IDictionary<TKey, TValue> pairs)
	{
		ArgumentNullException.ThrowIfNull(self);
		ArgumentNullException.ThrowIfNull(pairs);

		foreach (var (key, value) in pairs)
		{
			self.Add(key, value);
		}
	}
}
  1. Use the "Convert all extension methods...." refactoring on this type:
Image
  1. Note that the refactoring does this to the code:
namespace Spackle.Extensions;

/// <summary>
/// Provides extension methods for <see cref="IEnumerable{T}"/>-based objects.
/// </summary>
public static class IDictionaryExtensions
{
	extension<TKey, TValue>(IDictionary<TKey, TValue> self)
	{
		/// <summary>
		/// Adds key-value pairs to <paramref name="self"/>.
		/// </summary>
		/// <typeparam name="TKey">The type of the key.</typeparam>
		/// <typeparam name="TValue">The type of the value.</typeparam>
		/// <param name="self">The dictionary to add pairs to.</param>
		/// <param name="pairs">The pairs to add to <paramref name="self"/>.</param>
		/// <exception cref="ArgumentNullException">Thrown if <paramref name="self"/> or <paramref name="pairs"/> is <see langword="null" />.</exception>
		public void AddPairs(IDictionary<TKey, TValue> pairs)
		{
			ArgumentNullException.ThrowIfNull(self);
			ArgumentNullException.ThrowIfNull(pairs);

			foreach (var (key, value) in pairs)
			{
				self.Add(key, value);
			}
		}
	}
}

Expected Behavior:

The <typeparam> and <param> elements should move to where the extension block is.

Actual Behavior:

The comments are not changed.

According to this doc, these elements should be "on" the extension block, so leaving them on the method leads to an error. Unfortunately, this case has only one method - if there were more, they may be multiple references to <param> and/or <typeparam> so maybe the best action to take is to do nothing, but it also feels kind of wrong to leave those elements in place.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions