|
4 | 4 | // Created by: Alexey Kochetov
|
5 | 5 | // Created: 2007.09.21
|
6 | 6 |
|
7 |
| -using System; |
8 | 7 | using Xtensive.Orm.Model;
|
9 | 8 |
|
10 |
| -namespace Xtensive.Orm.Rse |
| 9 | +namespace Xtensive.Orm.Rse; |
| 10 | + |
| 11 | +/// <summary> |
| 12 | +/// Mapped column of the <see cref="RecordSetHeader"/>. |
| 13 | +/// </summary> |
| 14 | +[Serializable] |
| 15 | +public class MappedColumn(ColumnInfoRef columnInfoRef, string name, ColNum index, Type type) |
| 16 | + : Column(name, index, type) |
11 | 17 | {
|
12 | 18 | /// <summary>
|
13 |
| - /// Mapped column of the <see cref="RecordSetHeader"/>. |
| 19 | + /// Gets the reference that describes a column. |
14 | 20 | /// </summary>
|
15 |
| - [Serializable] |
16 |
| - public sealed class MappedColumn : Column |
17 |
| - { |
18 |
| - private const string ToStringFormat = "{0} = {1}"; |
19 |
| - |
20 |
| - /// <summary> |
21 |
| - /// Gets the reference that describes a column. |
22 |
| - /// </summary> |
23 |
| - public ColumnInfoRef ColumnInfoRef { get; } |
24 |
| - |
25 |
| - /// <inheritdoc/> |
26 |
| - public override string ToString() |
27 |
| - { |
28 |
| - return string.Format(ToStringFormat, base.ToString(), ColumnInfoRef); |
29 |
| - } |
30 |
| - |
31 |
| - /// <inheritdoc/> |
32 |
| - public override Column Clone(ColNum newIndex) |
33 |
| - { |
34 |
| - return new MappedColumn(ColumnInfoRef, Name, newIndex, Type); |
35 |
| - } |
| 21 | + public ColumnInfoRef ColumnInfoRef { get; } = columnInfoRef; |
36 | 22 |
|
37 |
| - /// <inheritdoc/> |
38 |
| - public override Column Clone(string newName) |
39 |
| - { |
40 |
| - return new MappedColumn(this, newName); |
41 |
| - } |
| 23 | + /// <inheritdoc/> |
| 24 | + public override string ToString() => $"{base.ToString()} = {ColumnInfoRef}"; |
42 | 25 |
|
43 |
| - // Constructors |
| 26 | + /// <inheritdoc/> |
| 27 | + public override Column Clone(ColNum newIndex) => new MappedColumn(ColumnInfoRef, Name, newIndex, Type); |
44 | 28 |
|
45 |
| - #region Basic constructors |
| 29 | + /// <inheritdoc/> |
| 30 | + public override Column Clone(string newName) => new DerivedMappedColumn(newName, Index, Type, Origin, ColumnInfoRef); |
46 | 31 |
|
47 |
| - /// <summary> |
48 |
| - /// Initializes a new instance of this class. |
49 |
| - /// </summary> |
50 |
| - /// <param name="name"><see cref="Column.Name"/> property value.</param> |
51 |
| - /// <param name="index"><see cref="Column.Index"/> property value.</param> |
52 |
| - /// <param name="type"><see cref="Column.Type"/> property value.</param> |
53 |
| - public MappedColumn(string name, ColNum index, Type type) |
54 |
| - : this(default, name, index, type) |
55 |
| - { |
56 |
| - } |
| 32 | + // Constructors |
57 | 33 |
|
58 |
| - /// <summary> |
59 |
| - /// Initializes a new instance of this class. |
60 |
| - /// </summary> |
61 |
| - /// <param name="columnInfoRef"><see cref="ColumnInfoRef"/> property value.</param> |
62 |
| - /// <param name="index"><see cref="Column.Index"/> property value.</param> |
63 |
| - /// <param name="type"><see cref="Column.Type"/> property value.</param> |
64 |
| - public MappedColumn(ColumnInfoRef columnInfoRef, ColNum index, Type type) |
65 |
| - : this(columnInfoRef, columnInfoRef.ColumnName, index, type) |
66 |
| - { |
67 |
| - } |
| 34 | + #region Basic constructors |
68 | 35 |
|
69 |
| - /// <summary> |
70 |
| - /// Initializes a new instance of this class. |
71 |
| - /// </summary> |
72 |
| - /// <param name="columnInfoRef"><see cref="ColumnInfoRef"/> property value.</param> |
73 |
| - /// <param name="name"><see cref="Column.Name"/> property value.</param> |
74 |
| - /// <param name="index"><see cref="Column.Index"/> property value.</param> |
75 |
| - /// <param name="type"><see cref="Column.Type"/> property value.</param> |
76 |
| - public MappedColumn(ColumnInfoRef columnInfoRef, string name, ColNum index, Type type) |
77 |
| - : base(name, index, type, null) |
78 |
| - { |
79 |
| - ColumnInfoRef = columnInfoRef; |
80 |
| - } |
81 |
| - |
82 |
| - #endregion |
| 36 | + /// <summary> |
| 37 | + /// Initializes a new instance of this class. |
| 38 | + /// </summary> |
| 39 | + /// <param name="name"><see cref="Column.Name"/> property value.</param> |
| 40 | + /// <param name="index"><see cref="Column.Index"/> property value.</param> |
| 41 | + /// <param name="type"><see cref="Column.Type"/> property value.</param> |
| 42 | + public MappedColumn(string name, ColNum index, Type type) |
| 43 | + : this(default, name, index, type) |
| 44 | + { |
| 45 | + } |
83 | 46 |
|
84 |
| - #region Clone constructors |
| 47 | + /// <summary> |
| 48 | + /// Initializes a new instance of this class. |
| 49 | + /// </summary> |
| 50 | + /// <param name="columnInfoRef"><see cref="ColumnInfoRef"/> property value.</param> |
| 51 | + /// <param name="index"><see cref="Column.Index"/> property value.</param> |
| 52 | + /// <param name="type"><see cref="Column.Type"/> property value.</param> |
| 53 | + public MappedColumn(ColumnInfoRef columnInfoRef, ColNum index, Type type) |
| 54 | + : this(columnInfoRef, columnInfoRef.ColumnName, index, type) |
| 55 | + { |
| 56 | + } |
85 | 57 |
|
86 |
| - private MappedColumn(MappedColumn column, string newName) |
87 |
| - : base(newName, column.Index, column.Type, column) |
88 |
| - { |
89 |
| - ColumnInfoRef = column.ColumnInfoRef; |
90 |
| - } |
| 58 | + #endregion |
91 | 59 |
|
92 |
| - private MappedColumn(MappedColumn column, ColNum newIndex) |
93 |
| - : base(column.Name, newIndex, column.Type, column) |
94 |
| - { |
95 |
| - ColumnInfoRef = column.ColumnInfoRef; |
96 |
| - } |
| 60 | +} |
97 | 61 |
|
98 |
| - #endregion |
99 |
| - } |
| 62 | +// The purpose of this class is minimize allocation size of `MappedColumn` |
| 63 | +// Non self-referencing `Origin` property is a rare case |
| 64 | +internal sealed class DerivedMappedColumn(string name, ColNum index, Type type, Column origin, ColumnInfoRef columnInfoRef) |
| 65 | + : MappedColumn(columnInfoRef, name, index, type) |
| 66 | +{ |
| 67 | + public override Column Origin => origin ?? this; |
100 | 68 | }
|
0 commit comments