Skip to content

Commit f35aadc

Browse files
committed
Use records
1 parent 188e053 commit f35aadc

File tree

7 files changed

+8
-101
lines changed

7 files changed

+8
-101
lines changed

src/TfvcMigrator/BranchIdentity.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace TfvcMigrator;
22

33
[DebuggerDisplay("{ToString(),nq}")]
4-
public readonly struct BranchIdentity : IEquatable<BranchIdentity>
4+
public readonly record struct BranchIdentity
55
{
66
public BranchIdentity(int creationChangeset, string path)
77
{
@@ -32,11 +32,6 @@ public override string ToString()
3232
return $"CS{CreationChangeset}:{Path}";
3333
}
3434

35-
public override bool Equals(object? obj)
36-
{
37-
return obj is BranchIdentity identity && Equals(identity);
38-
}
39-
4035
public bool Equals(BranchIdentity other)
4136
{
4237
return CreationChangeset == other.CreationChangeset
@@ -47,14 +42,4 @@ public override int GetHashCode()
4742
{
4843
return HashCode.Combine(CreationChangeset, Path.GetHashCode(StringComparison.OrdinalIgnoreCase));
4944
}
50-
51-
public static bool operator ==(BranchIdentity left, BranchIdentity right)
52-
{
53-
return left.Equals(right);
54-
}
55-
56-
public static bool operator !=(BranchIdentity left, BranchIdentity right)
57-
{
58-
return !(left == right);
59-
}
6045
}

src/TfvcMigrator/Operations/BranchOperation.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace TfvcMigrator.Operations;
22

33
[DebuggerDisplay("{ToString(),nq}")]
4-
public sealed class BranchOperation : TopologicalOperation, IEquatable<BranchOperation?>
4+
public sealed record BranchOperation : TopologicalOperation
55
{
66
public BranchOperation(BranchIdentity sourceBranch, int sourceBranchChangeset, string sourceBranchPath, BranchIdentity newBranch)
77
{
@@ -27,11 +27,6 @@ public BranchOperation(BranchIdentity sourceBranch, int sourceBranchChangeset, s
2727

2828
public override string ToString() => $"CS{Changeset}: Branch {SourceBranchPath} at CS{SourceBranchChangeset} to {NewBranch.Path}";
2929

30-
public override bool Equals(object? obj)
31-
{
32-
return Equals(obj as BranchOperation);
33-
}
34-
3530
public bool Equals(BranchOperation? other)
3631
{
3732
return other != null &&
Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
11
namespace TfvcMigrator.Operations;
22

33
[DebuggerDisplay("{ToString(),nq}")]
4-
public sealed class DeleteOperation : TopologicalOperation, IEquatable<DeleteOperation?>
4+
public sealed record DeleteOperation(int Changeset, BranchIdentity Branch) : TopologicalOperation
55
{
6-
public DeleteOperation(int changeset, BranchIdentity branch)
7-
{
8-
Changeset = changeset;
9-
Branch = branch;
10-
}
11-
12-
public override int Changeset { get; }
13-
public BranchIdentity Branch { get; }
14-
15-
public override bool Equals(object? obj)
16-
{
17-
return Equals(obj as DeleteOperation);
18-
}
19-
20-
public bool Equals(DeleteOperation? other)
21-
{
22-
return other != null &&
23-
Changeset == other.Changeset &&
24-
Branch.Equals(other.Branch);
25-
}
26-
27-
public override int GetHashCode()
28-
{
29-
return HashCode.Combine(Changeset, Branch);
30-
}
6+
public override int Changeset { get; } = Changeset;
317

328
public override string ToString() => $"CS{Changeset}: Delete {Branch.Path}";
339
}

src/TfvcMigrator/Operations/MergeOperation.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace TfvcMigrator.Operations;
22

33
[DebuggerDisplay("{ToString(),nq}")]
4-
public sealed class MergeOperation : TopologicalOperation, IEquatable<MergeOperation?>
4+
public sealed record MergeOperation : TopologicalOperation
55
{
66
public MergeOperation(int changeset, BranchIdentity sourceBranch, int sourceBranchChangeset, string sourceBranchPath, BranchIdentity targetBranch, string targetBranchPath)
77
{
@@ -31,11 +31,6 @@ public MergeOperation(int changeset, BranchIdentity sourceBranch, int sourceBran
3131

3232
public override string ToString() => $"CS{Changeset}: Merge {SourceBranchPath} at {SourceBranchChangeset} to {TargetBranchPath}";
3333

34-
public override bool Equals(object? obj)
35-
{
36-
return Equals(obj as MergeOperation);
37-
}
38-
3934
public bool Equals(MergeOperation? other)
4035
{
4136
return other != null &&
Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,9 @@
11
namespace TfvcMigrator.Operations;
22

33
[DebuggerDisplay("{ToString(),nq}")]
4-
public sealed class RenameOperation : TopologicalOperation, IEquatable<RenameOperation?>
4+
public sealed record RenameOperation(BranchIdentity OldIdentity, BranchIdentity NewIdentity) : TopologicalOperation
55
{
6-
public RenameOperation(BranchIdentity oldIdentity, BranchIdentity newIdentity)
7-
{
8-
OldIdentity = oldIdentity;
9-
NewIdentity = newIdentity;
10-
}
11-
126
public override int Changeset => NewIdentity.CreationChangeset;
13-
public BranchIdentity OldIdentity { get; }
14-
public BranchIdentity NewIdentity { get; }
157

168
public override string ToString() => $"CS{Changeset}: Rename {OldIdentity.Path} to {NewIdentity.Path}";
17-
18-
public override bool Equals(object? obj)
19-
{
20-
return Equals(obj as RenameOperation);
21-
}
22-
23-
public bool Equals(RenameOperation? other)
24-
{
25-
return other != null &&
26-
OldIdentity.Equals(other.OldIdentity) &&
27-
NewIdentity.Equals(other.NewIdentity);
28-
}
29-
30-
public override int GetHashCode()
31-
{
32-
return HashCode.Combine(OldIdentity, NewIdentity);
33-
}
349
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
namespace TfvcMigrator.Operations;
22

3-
public abstract class TopologicalOperation
3+
public abstract record TopologicalOperation
44
{
55
public abstract int Changeset { get; }
66

77
public abstract override string ToString();
8-
public abstract override bool Equals(object? obj);
9-
public abstract override int GetHashCode();
108
}

src/TfvcMigrator/RootPathChange.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
namespace TfvcMigrator;
22

33
[DebuggerDisplay("{ToString(),nq}")]
4-
public sealed class RootPathChange : IEquatable<RootPathChange?>
4+
public sealed record RootPathChange
55
{
66
public RootPathChange(int changeset, string newSourceRootPath)
77
{
@@ -18,22 +18,5 @@ public RootPathChange(int changeset, string newSourceRootPath)
1818
public int Changeset { get; }
1919
public string NewSourceRootPath { get; }
2020

21-
public override bool Equals(object? obj)
22-
{
23-
return Equals(obj as RootPathChange);
24-
}
25-
26-
public bool Equals(RootPathChange? other)
27-
{
28-
return other != null &&
29-
Changeset == other.Changeset &&
30-
NewSourceRootPath == other.NewSourceRootPath;
31-
}
32-
33-
public override int GetHashCode()
34-
{
35-
return HashCode.Combine(Changeset, NewSourceRootPath);
36-
}
37-
3821
public override string ToString() => $"CS{Changeset}:{NewSourceRootPath}";
3922
}

0 commit comments

Comments
 (0)