Skip to content

Commit c369643

Browse files
authored
Merge pull request #1109 from unsafePtr/seal-sbe-primitive-types
[C#] refactor: seal PrimitiveValue and PrimitiveType, make ThrowHelper static
2 parents e1e1569 + c386066 commit c369643

3 files changed

Lines changed: 13 additions & 18 deletions

File tree

csharp/sbe-dll/PrimitiveType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
/// </tbody>
7272
/// </table>
7373
/// </summary>
74-
public class PrimitiveType
74+
public sealed class PrimitiveType
7575
{
7676
/// <summary>
7777
/// Primitive type representation for SBE type CHAR

csharp/sbe-dll/PrimitiveValue.cs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ namespace Org.SbeTool.Sbe.Dll
7474
/// </tbody>
7575
/// </table>
7676
/// </summary>
77-
public class PrimitiveValue
77+
public sealed class PrimitiveValue
7878
{
7979
private enum Representation
8080
{
@@ -485,26 +485,21 @@ public override string ToString()
485485
/// <returns> equivalence of values </returns>
486486
public override bool Equals(object value)
487487
{
488-
if (null != value && this.GetType().Equals(value.GetType()))
488+
if (value is PrimitiveValue rhs && _representation == rhs._representation)
489489
{
490-
var rhs = (PrimitiveValue) value;
491-
492-
if (_representation == rhs._representation)
490+
switch (_representation)
493491
{
494-
switch (_representation)
495-
{
496-
case Representation.Long:
497-
return _longValue == rhs._longValue;
492+
case Representation.Long:
493+
return _longValue == rhs._longValue;
498494

499-
case Representation.ULong:
500-
return _unsignedLongValue == rhs._unsignedLongValue;
495+
case Representation.ULong:
496+
return _unsignedLongValue == rhs._unsignedLongValue;
501497

502-
case Representation.Double:
503-
return BitConverter.DoubleToInt64Bits(_doubleValue) == BitConverter.DoubleToInt64Bits(rhs._doubleValue);
498+
case Representation.Double:
499+
return BitConverter.DoubleToInt64Bits(_doubleValue) == BitConverter.DoubleToInt64Bits(rhs._doubleValue);
504500

505-
case Representation.ByteArray:
506-
return _byteArrayValue.SequenceEqual(rhs._byteArrayValue);
507-
}
501+
case Representation.ByteArray:
502+
return _byteArrayValue.SequenceEqual(rhs._byteArrayValue);
508503
}
509504
}
510505

csharp/sbe-dll/ThrowHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace Org.SbeTool.Sbe.Dll
66
/// Helper class that provides non-returning methods that throw common exception
77
/// from the generated C# code
88
/// </summary>
9-
public class ThrowHelper
9+
public static class ThrowHelper
1010
{
1111
/// <summary>
1212
/// Throws a <see cref="ArgumentOutOfRangeException"/> when the "count" parameter is out of range

0 commit comments

Comments
 (0)