Skip to content

Commit 9ff85a2

Browse files
committed
Refactor
1 parent 4be4919 commit 9ff85a2

File tree

1 file changed

+65
-92
lines changed

1 file changed

+65
-92
lines changed

Orm/Xtensive.Orm/Orm/Rse/Column.cs

Lines changed: 65 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -4,111 +4,84 @@
44
// Created by: Elena Vakhtina
55
// Created: 2008.09.09
66

7-
namespace Xtensive.Orm.Rse
7+
namespace Xtensive.Orm.Rse;
8+
9+
/// <summary>
10+
/// Base class for any column of the <see cref="RecordSetHeader"/>.
11+
/// </summary>
12+
[Serializable]
13+
public abstract class Column(string name, ColNum index, Type type) : IEquatable<Column>
814
{
915
/// <summary>
10-
/// Base class for any column of the <see cref="RecordSetHeader"/>.
16+
/// Gets origin <see cref="Column"/> for this instance.
1117
/// </summary>
12-
[Serializable]
13-
public abstract class Column : IEquatable<Column>
14-
{
15-
private const string ToStringFormat = "{0} {1} ({2})";
16-
17-
/// <summary>
18-
/// Gets origin <see cref="Column"/> for this instance.
19-
/// </summary>
20-
public virtual Column Origin => this;
21-
22-
/// <summary>
23-
/// Gets the column name.
24-
/// </summary>
25-
public string Name { get; private set; }
26-
27-
/// <summary>
28-
/// Gets the column index.
29-
/// </summary>
30-
public ColNum Index { get; }
31-
32-
/// <summary>
33-
/// Gets the column type.
34-
/// </summary>
35-
public Type Type { get; private set; }
36-
37-
#region Equals, GetHashCode, ==, !=
18+
public virtual Column Origin => this;
3819

39-
/// <inheritdoc/>
40-
public bool Equals(Column other) =>
41-
other is not null && (ReferenceEquals(this, other) || Name == other.Name);
42-
43-
/// <inheritdoc/>
44-
public override bool Equals(object obj) => obj is Column other && Equals(other);
20+
/// <summary>
21+
/// Gets the column name.
22+
/// </summary>
23+
public string Name { get; } = name;
4524

46-
/// <inheritdoc/>
47-
public override int GetHashCode() => Name.GetHashCode();
25+
/// <summary>
26+
/// Gets the column index.
27+
/// </summary>
28+
public ColNum Index { get; } = index;
4829

49-
/// <summary>
50-
/// Implements the operator ==.
51-
/// </summary>
52-
/// <param name="left">The left.</param>
53-
/// <param name="right">The right.</param>
54-
/// <returns>
55-
/// The result of the operator.
56-
/// </returns>
57-
public static bool operator ==(Column left, Column right) => left?.Equals(right) ?? right is null;
30+
/// <summary>
31+
/// Gets the column type.
32+
/// </summary>
33+
public Type Type { get; } = type;
5834

59-
/// <summary>
60-
/// Implements the operator !=.
61-
/// </summary>
62-
/// <param name="left">The left.</param>
63-
/// <param name="right">The right.</param>
64-
/// <returns>
65-
/// The result of the operator.
66-
/// </returns>
67-
public static bool operator !=(Column left, Column right) => !(left == right);
35+
/// <inheritdoc/>
36+
public bool Equals(Column other) =>
37+
other is not null && (ReferenceEquals(this, other) || Name == other.Name);
6838

69-
#endregion
39+
/// <inheritdoc/>
40+
public override bool Equals(object obj) => obj is Column other && Equals(other);
7041

71-
/// <inheritdoc/>
72-
public override string ToString()
73-
{
74-
return string.Format(ToStringFormat, Type.Name, Name, Index);
75-
}
42+
/// <inheritdoc/>
43+
public override int GetHashCode() => Name.GetHashCode();
7644

77-
/// <summary>
78-
/// Creates clone of the column, but with another <see cref="Index"/>.
79-
/// </summary>
80-
/// <param name="newIndex">The new index value.</param>
81-
/// <returns>Clone of the column, but with another <see cref="Index"/>.</returns>
82-
public abstract Column Clone(ColNum newIndex);
45+
/// <summary>
46+
/// Implements the operator ==.
47+
/// </summary>
48+
/// <param name="left">The left.</param>
49+
/// <param name="right">The right.</param>
50+
/// <returns>
51+
/// The result of the operator.
52+
/// </returns>
53+
public static bool operator ==(Column left, Column right) => left?.Equals(right) ?? right is null;
8354

84-
/// <summary>
85-
/// Creates clone of the column, but with another <see cref="Name"/>.
86-
/// </summary>
87-
/// <param name="newName">The new name value.</param>
88-
/// <returns>Clone of the column, but with another <see cref="Name"/>.</returns>
89-
public abstract Column Clone(string newName);
55+
/// <summary>
56+
/// Implements the operator !=.
57+
/// </summary>
58+
/// <param name="left">The left.</param>
59+
/// <param name="right">The right.</param>
60+
/// <returns>
61+
/// The result of the operator.
62+
/// </returns>
63+
public static bool operator !=(Column left, Column right) => !(left == right);
9064

65+
/// <inheritdoc/>
66+
public override string ToString() => $"{Type.Name} {Name} ({Index})";
9167

92-
// Constructors
68+
/// <summary>
69+
/// Creates clone of the column, but with another <see cref="Index"/>.
70+
/// </summary>
71+
/// <param name="newIndex">The new index value.</param>
72+
/// <returns>Clone of the column, but with another <see cref="Index"/>.</returns>
73+
public abstract Column Clone(ColNum newIndex);
9374

94-
/// <summary>
95-
/// Initializes a new instance of this class..
96-
/// </summary>
97-
/// <param name="name"><see cref="Name"/> property value.</param>
98-
/// <param name="index"><see cref="Index"/> property value.</param>
99-
/// <param name="type"><see cref="Type"/> property value.</param>
100-
/// <param name="originalColumn">Original column.</param>
101-
protected Column(string name, ColNum index, Type type)
102-
{
103-
Name = name;
104-
Index = index;
105-
Type = type;
106-
}
107-
}
75+
/// <summary>
76+
/// Creates clone of the column, but with another <see cref="Name"/>.
77+
/// </summary>
78+
/// <param name="newName">The new name value.</param>
79+
/// <returns>Clone of the column, but with another <see cref="Name"/>.</returns>
80+
public abstract Column Clone(string newName);
81+
}
10882

109-
public abstract class DerivedColumn(string name, ColNum index, Type type, Column origin)
110-
: Column(name, index, type)
111-
{
112-
public override Column Origin => origin ?? this;
113-
}
83+
public abstract class DerivedColumn(string name, ColNum index, Type type, Column origin)
84+
: Column(name, index, type)
85+
{
86+
public override Column Origin => origin ?? this;
11487
}

0 commit comments

Comments
 (0)