Skip to content
Draft
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
Expand Up @@ -43,6 +43,12 @@ public enum BackCompatibilityChangeCategory
/// <summary>A back-compat overload of a client method was added because new optional non-body parameter(s) were introduced relative to the last contract.</summary>
SvcMethodNewOptionalParameterOverloadAdded,

/// <summary>A back-compat overload of a client method was added because a value-type parameter's nullability was removed (e.g. <c>T?</c> -&gt; <c>T</c>) relative to the last contract.</summary>
SvcMethodParameterNullabilityChangeOverloadAdded,

/// <summary>A back-compat reduced-arity overload of a client method was added because a nullable parameter changed from optional to required relative to the last contract.</summary>
SvcMethodParameterOptionalityRestorationOverloadAdded,

/// <summary>A back-compat change was skipped because the removal was accepted in the ApiCompat baseline.</summary>
BaselineAcceptedRemovalSkipped,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ public void WriteBufferedMessages()
BackCompatibilityChangeCategory.ModelFactoryMethodAdded => "Model Factory Method Added For Back-Compat",
BackCompatibilityChangeCategory.ModelFactoryMethodSkipped => "Model Factory Method Back-Compat Skipped",
BackCompatibilityChangeCategory.SvcMethodNewOptionalParameterOverloadAdded => "Method Back-Compat Overload Added For New Optional Parameter",
BackCompatibilityChangeCategory.SvcMethodParameterNullabilityChangeOverloadAdded => "Method Back-Compat Overload Added For Parameter Nullability Change",
BackCompatibilityChangeCategory.SvcMethodParameterOptionalityRestorationOverloadAdded => "Method Back-Compat Overload Added For Parameter Optionality Change",
BackCompatibilityChangeCategory.BaselineAcceptedRemovalSkipped => "Back-Compat Skipped For ApiCompat Baseline Accepted Removal",
BackCompatibilityChangeCategory.EnumMemberAddedFromLastContract => "Enum Member Added From Last Contract",
_ => category.ToString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,25 @@ public bool AreNamesEqual(CSharpType? other)
return true;
}

/// <summary>
/// Checks whether two <see cref="CSharpType"/> instances have equal names, optionally also requiring
/// their nullability to match. Unlike <see cref="Equals(CSharpType, bool)"/>, this compares only
/// names (and generic argument names), which is useful when comparing against a type read from source
/// that may not carry the same metadata (for example an extensible enum, read back as a struct).
/// </summary>
/// <param name="other">The instance to compare to.</param>
/// <param name="checkNullability">When <c>true</c>, the two types must also have the same <see cref="IsNullable"/> value.</param>
/// <returns><c>true</c> if the names (and, when requested, nullability) are equal; <c>false</c> otherwise.</returns>
internal bool AreNamesEqual(CSharpType? other, bool checkNullability)
{
if (!AreNamesEqual(other))
{
return false;
}

return !checkNullability || IsNullable == other!.IsNullable;
}

private bool IsNameMatch(CSharpType other)
{
if (string.IsNullOrEmpty(Namespace))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,18 @@ public void Update(string? name = default, FormattableString? description = defa
}
}

public static readonly IEqualityComparer<MethodSignatureBase> SignatureComparer = new MethodSignatureBaseEqualityComparer();
public static readonly IEqualityComparer<MethodSignatureBase> SignatureComparer = new MethodSignatureBaseEqualityComparer(checkNullability: false);
internal static readonly IEqualityComparer<MethodSignatureBase> SignatureComparerIncludingNullability = new MethodSignatureBaseEqualityComparer(checkNullability: true);

private class MethodSignatureBaseEqualityComparer : IEqualityComparer<MethodSignatureBase>
{
private readonly bool _checkNullability;

public MethodSignatureBaseEqualityComparer(bool checkNullability)
{
_checkNullability = checkNullability;
}

public bool Equals(MethodSignatureBase? x, MethodSignatureBase? y)
{
if (ReferenceEquals(x, y))
Expand Down Expand Up @@ -160,7 +168,7 @@ public bool Equals(MethodSignatureBase? x, MethodSignatureBase? y)

for (int i = 0; i < x.Parameters.Count; i++)
{
if (!x.Parameters[i].Type.AreNamesEqual(y.Parameters[i].Type))
if (!x.Parameters[i].Type.AreNamesEqual(y.Parameters[i].Type, _checkNullability))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ protected internal virtual IReadOnlyList<MethodProvider> BuildMethodsForBackComp
}

BackCompatHelper.RestorePreviousParameterNames(this, methods);
BackCompatHelper.AddOverloadsForNewOptionalParameters(this, methods);
BackCompatHelper.AddBackCompatOverloads(this, methods);

return methods;
}
Expand Down
Loading
Loading