Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/PublicApiGenerator/CSharpOperatorKeyword.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace PublicApiGenerator;

internal static class CSharpOperatorKeyword
{
private static readonly IDictionary<string, string> OperatorNameMap = new Dictionary<string, string>
private static readonly Dictionary<string, string> _operatorNameMap = new()
{
{ "op_False", "false" },
{ "op_True", "true" },
Expand Down Expand Up @@ -32,6 +32,6 @@ internal static class CSharpOperatorKeyword

public static string Get(string memberName)
{
return OperatorNameMap.TryGetValue(memberName, out string mappedMemberName) ? "operator " + mappedMemberName : memberName;
return _operatorNameMap.TryGetValue(memberName, out string mappedMemberName) ? "operator " + mappedMemberName : memberName;
}
}
23 changes: 22 additions & 1 deletion src/PublicApiGenerator/CodeTypeDeclarationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ namespace PublicApiGenerator;

internal static class CodeTypeDeclarationExtensions
{
private static readonly Dictionary<string, string> _map = new()
{
{ "System.Int16", "short" },
{ "System.Int32", "int" },
{ "System.Int64", "long" },
{ "System.String", "string" },
{ "System.Object", "object" },
{ "System.Boolean", "bool" },
{ "System.Char", "char" },
{ "System.Byte", "byte" },
{ "System.UInt16", "ushort" },
{ "System.UInt32", "uint" },
{ "System.UInt64", "ulong" },
{ "System.SByte", "sbyte" },
{ "System.Single", "float" },
{ "System.Double", "double" },
{ "System.Decimal", "decimal" },
};

private static string MapToAlias(string type) => _map.TryGetValue(type, out string alias) ? alias : type;

public static CodeTypeDeclarationEx Sort(this CodeTypeDeclarationEx original)
{
if (original.IsEnum)
Expand Down Expand Up @@ -100,7 +121,7 @@ string GetBaseType(CodeTypeReference r)
{
return r.BaseType == "System.Nullable`1" && r.TypeArguments.Count == 1
? r.TypeArguments[0].BaseType + "?"
: r.BaseType;
: MapToAlias(r.BaseType);
}

var baseType = string.CompareOrdinal(GetBaseType(x), GetBaseType(y));
Expand Down
32 changes: 32 additions & 0 deletions src/PublicApiGeneratorTests/AliasOrdering.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using PublicApiGeneratorTests.Examples;

namespace PublicApiGeneratorTests
{
public class AliasOrdering : ApiGeneratorTestsBase
{
[Fact]
public void Should_Order_Class_First()
{
AssertPublicApi(typeof(ClassWithAliasedTypes),
"""
namespace PublicApiGeneratorTests.Examples
{
public static class ClassWithAliasedTypes
{
public static void ShouldBeNegative(this float actual, string? customMessage = null) { }
public static void ShouldBeNegative(this short actual, string? customMessage = null) { }
}
}
""");
}
}

namespace Examples
{
public static class ClassWithAliasedTypes
{
public static void ShouldBeNegative(this short actual, string? customMessage = null) { }
public static void ShouldBeNegative(this float actual, string? customMessage = null) { }
}
}
}
2 changes: 1 addition & 1 deletion src/PublicApiGeneratorTests/Expressions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ namespace PublicApiGeneratorTests.Examples
{
public class ClassWithExpressions<TSourceType>
{
public ClassWithExpressions(params System.Linq.Expressions.Expression<System.Func<int, object>>[] expr1) { }
public ClassWithExpressions(params System.Linq.Expressions.Expression<System.Func<TSourceType, object?>>[] expr2) { }
public ClassWithExpressions(params System.Linq.Expressions.Expression<System.Func<int, object>>[] expr1) { }
public ClassWithExpressions(System.Linq.Expressions.Expression<System.Func<TSourceType, object>?> expr3) { }
public ClassWithExpressions(System.Linq.Expressions.Expression<System.Func<int, object>>? expr4) { }
}
Expand Down