Skip to content

Commit

Permalink
Merge pull request #193 from stakx/overloaded-operators-syntax
Browse files Browse the repository at this point in the history
Fix syntax for overloaded operator methods
  • Loading branch information
danielmarbach committed Jun 18, 2020
2 parents 1e377fa + 57c46b1 commit a1cbb75
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
4 changes: 3 additions & 1 deletion src/PublicApiGenerator/CSharpOperatorKeyword.cs
Expand Up @@ -6,6 +6,8 @@ internal static class CSharpOperatorKeyword
{
static readonly IDictionary<string, string> OperatorNameMap = new Dictionary<string, string>
{
{ "op_False", "false" },
{ "op_True", "true" },
{ "op_Addition", "+" },
{ "op_UnaryPlus", "+" },
{ "op_Subtraction", "-" },
Expand All @@ -32,7 +34,7 @@ internal static class CSharpOperatorKeyword

public static string Get(string memberName)
{
return OperatorNameMap.TryGetValue(memberName, out string mappedMemberName) ? mappedMemberName : memberName;
return OperatorNameMap.TryGetValue(memberName, out string mappedMemberName) ? "operator " + mappedMemberName : memberName;
}
}
}
48 changes: 24 additions & 24 deletions src/PublicApiGeneratorTests/Operator_order.cs
Expand Up @@ -14,14 +14,14 @@ public void Should_sort_unary_operators()
public class ClassWithUnaryOperators
{
public ClassWithUnaryOperators() { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators !(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators +(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators ++(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators -(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators --(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static bool op_False(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static bool op_True(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators ~(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators operator !(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators operator +(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators operator ++(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators operator -(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators operator --(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static bool operator false(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static bool operator true(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
public static PublicApiGeneratorTests.Examples.ClassWithUnaryOperators operator ~(PublicApiGeneratorTests.Examples.ClassWithUnaryOperators first) { }
}
}");
}
Expand All @@ -35,16 +35,16 @@ public void Should_sort_binary_operators()
public class ClassWithBinaryOperators
{
public ClassWithBinaryOperators() { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators %(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators &(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators *(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators +(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators -(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators /(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators <<(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, int second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators >>(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, int second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators ^(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators |(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator %(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator &(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator *(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator +(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator -(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator /(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator <<(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, int second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator >>(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, int second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator ^(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
public static PublicApiGeneratorTests.Examples.ClassWithBinaryOperators operator |(PublicApiGeneratorTests.Examples.ClassWithBinaryOperators first, PublicApiGeneratorTests.Examples.ClassWithBinaryOperators second) { }
}
}");
}
Expand All @@ -58,12 +58,12 @@ public void Should_sort_comparison_operators()
public class ClassWithComparisonOperators
{
public ClassWithComparisonOperators() { }
public static bool !=(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool <(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool <=(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool ==(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool >(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool >=(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool operator !=(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool operator <(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool operator <=(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool operator ==(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool operator >(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
public static bool operator >=(PublicApiGeneratorTests.Examples.ClassWithComparisonOperators first, PublicApiGeneratorTests.Examples.ClassWithComparisonOperators second) { }
}
}");
}
Expand Down
2 changes: 1 addition & 1 deletion src/PublicApiGeneratorTests/Operator_visibility.cs
Expand Up @@ -14,7 +14,7 @@ public void Should_show_custom_operators()
public class ClassWithOperator
{
public ClassWithOperator() { }
public static PublicApiGeneratorTests.Examples.ClassWithOperator +(PublicApiGeneratorTests.Examples.ClassWithOperator first, PublicApiGeneratorTests.Examples.ClassWithOperator second) { }
public static PublicApiGeneratorTests.Examples.ClassWithOperator operator +(PublicApiGeneratorTests.Examples.ClassWithOperator first, PublicApiGeneratorTests.Examples.ClassWithOperator second) { }
}
}");
}
Expand Down

0 comments on commit a1cbb75

Please sign in to comment.