diff --git a/Orm/Xtensive.Orm/Orm/Rse/AggregateColumn.cs b/Orm/Xtensive.Orm/Orm/Rse/AggregateColumn.cs
index a00dfec82..1c937a61e 100644
--- a/Orm/Xtensive.Orm/Orm/Rse/AggregateColumn.cs
+++ b/Orm/Xtensive.Orm/Orm/Rse/AggregateColumn.cs
@@ -12,7 +12,7 @@ namespace Xtensive.Orm.Rse
/// Aggregate column of the .
///
[Serializable]
- public sealed class AggregateColumn : Column
+ public sealed class AggregateColumn : DerivedColumn
{
private const string ToStringFormat = "{0} = {1} on ({2})";
@@ -70,14 +70,14 @@ public AggregateColumn(AggregateColumnDescriptor descriptor, ColNum index, Type
#region Clone constructors
private AggregateColumn(AggregateColumn column, string newName)
- : base(newName, column.Index, column.Type, column)
+ : base(newName, column.Index, column.Type, column.Origin)
{
AggregateType = column.AggregateType;
SourceIndex = column.SourceIndex;
}
private AggregateColumn(AggregateColumn column, ColNum newIndex)
- : base(column.Name, newIndex, column.Type, column)
+ : base(column.Name, newIndex, column.Type, column.Origin)
{
AggregateType = column.AggregateType;
SourceIndex = column.SourceIndex;
@@ -85,4 +85,4 @@ private AggregateColumn(AggregateColumn column, ColNum newIndex)
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/Orm/Xtensive.Orm/Orm/Rse/CalculatedColumn.cs b/Orm/Xtensive.Orm/Orm/Rse/CalculatedColumn.cs
index abbea1ce3..1abb8d19d 100644
--- a/Orm/Xtensive.Orm/Orm/Rse/CalculatedColumn.cs
+++ b/Orm/Xtensive.Orm/Orm/Rse/CalculatedColumn.cs
@@ -18,7 +18,7 @@ namespace Xtensive.Orm.Rse
/// Calculated column of the .
///
[Serializable]
- public sealed class CalculatedColumn : Column
+ public sealed class CalculatedColumn : DerivedColumn
{
private const string ToStringFormat = "{0} = {1}";
@@ -63,17 +63,17 @@ public CalculatedColumn(CalculatedColumnDescriptor descriptor, ColNum index)
#region Clone constructors
private CalculatedColumn(CalculatedColumn column, string newName)
- : base(newName, column.Index, column.Type, column)
+ : base(newName, column.Index, column.Type, column.Origin)
{
Expression = column.Expression;
}
private CalculatedColumn(CalculatedColumn column, ColNum newIndex)
- : base(column.Name, newIndex, column.Type, column)
+ : base(column.Name, newIndex, column.Type, column.Origin)
{
Expression = column.Expression;
}
#endregion
}
-}
\ No newline at end of file
+}
diff --git a/Orm/Xtensive.Orm/Orm/Rse/Column.cs b/Orm/Xtensive.Orm/Orm/Rse/Column.cs
index 8784ab23b..623f42913 100644
--- a/Orm/Xtensive.Orm/Orm/Rse/Column.cs
+++ b/Orm/Xtensive.Orm/Orm/Rse/Column.cs
@@ -4,109 +4,84 @@
// Created by: Elena Vakhtina
// Created: 2008.09.09
-using System;
+namespace Xtensive.Orm.Rse;
-
-namespace Xtensive.Orm.Rse
+///
+/// Base class for any column of the .
+///
+[Serializable]
+public abstract class Column(string name, ColNum index, Type type) : IEquatable
{
///
- /// Base class for any column of the .
+ /// Gets origin for this instance.
///
- [Serializable]
- public abstract class Column : IEquatable
- {
- private const string ToStringFormat = "{0} {1} ({2})";
-
- ///
- /// Gets origin for this instance.
- ///
- public Column Origin { get; private set; }
-
- ///
- /// Gets the column name.
- ///
- public string Name { get; private set; }
-
- ///
- /// Gets the column index.
- ///
- public ColNum Index { get; }
-
- ///
- /// Gets the column type.
- ///
- public Type Type { get; private set; }
-
- #region Equals, GetHashCode, ==, !=
+ public virtual Column Origin => this;
- ///
- public bool Equals(Column other) =>
- other is not null && (ReferenceEquals(this, other) || Name == other.Name);
+ ///
+ /// Gets the column name.
+ ///
+ public string Name { get; } = name;
- ///
- public override bool Equals(object obj) => obj is Column other && Equals(other);
+ ///
+ /// Gets the column index.
+ ///
+ public ColNum Index { get; } = index;
- ///
- public override int GetHashCode() => Name.GetHashCode();
+ ///
+ /// Gets the column type.
+ ///
+ public Type Type { get; } = type;
- ///
- /// Implements the operator ==.
- ///
- /// The left.
- /// The right.
- ///
- /// The result of the operator.
- ///
- public static bool operator ==(Column left, Column right) => left?.Equals(right) ?? right is null;
+ ///
+ public bool Equals(Column other) =>
+ other is not null && (ReferenceEquals(this, other) || Name == other.Name);
- ///
- /// Implements the operator !=.
- ///
- /// The left.
- /// The right.
- ///
- /// The result of the operator.
- ///
- public static bool operator !=(Column left, Column right) => !(left == right);
+ ///
+ public override bool Equals(object obj) => obj is Column other && Equals(other);
- #endregion
+ ///
+ public override int GetHashCode() => Name.GetHashCode();
- ///
- public override string ToString()
- {
- return string.Format(ToStringFormat, Type.Name, Name, Index);
- }
+ ///
+ /// Implements the operator ==.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static bool operator ==(Column left, Column right) => left?.Equals(right) ?? right is null;
- ///
- /// Creates clone of the column, but with another .
- ///
- /// The new index value.
- /// Clone of the column, but with another .
- public abstract Column Clone(ColNum newIndex);
+ ///
+ /// Implements the operator !=.
+ ///
+ /// The left.
+ /// The right.
+ ///
+ /// The result of the operator.
+ ///
+ public static bool operator !=(Column left, Column right) => !(left == right);
- ///
- /// Creates clone of the column, but with another .
- ///
- /// The new name value.
- /// Clone of the column, but with another .
- public abstract Column Clone(string newName);
+ ///
+ public override string ToString() => $"{Type.Name} {Name} ({Index})";
+ ///
+ /// Creates clone of the column, but with another .
+ ///
+ /// The new index value.
+ /// Clone of the column, but with another .
+ public abstract Column Clone(ColNum newIndex);
- // Constructors
+ ///
+ /// Creates clone of the column, but with another .
+ ///
+ /// The new name value.
+ /// Clone of the column, but with another .
+ public abstract Column Clone(string newName);
+}
- ///
- /// Initializes a new instance of this class..
- ///
- /// property value.
- /// property value.
- /// property value.
- /// Original column.
- protected Column(string name, ColNum index, Type type, Column originalColumn)
- {
- Name = name;
- Index = index;
- Type = type;
- Origin = originalColumn is null ? this : originalColumn.Origin;
- }
- }
+public abstract class DerivedColumn(string name, ColNum index, Type type, Column origin)
+ : Column(name, index, type)
+{
+ public override Column Origin => origin ?? this;
}
diff --git a/Orm/Xtensive.Orm/Orm/Rse/MappedColumn.cs b/Orm/Xtensive.Orm/Orm/Rse/MappedColumn.cs
index 157025599..5d903cba3 100644
--- a/Orm/Xtensive.Orm/Orm/Rse/MappedColumn.cs
+++ b/Orm/Xtensive.Orm/Orm/Rse/MappedColumn.cs
@@ -4,97 +4,65 @@
// Created by: Alexey Kochetov
// Created: 2007.09.21
-using System;
using Xtensive.Orm.Model;
-namespace Xtensive.Orm.Rse
+namespace Xtensive.Orm.Rse;
+
+///
+/// Mapped column of the .
+///
+[Serializable]
+public class MappedColumn(ColumnInfoRef columnInfoRef, string name, ColNum index, Type type)
+ : Column(name, index, type)
{
///
- /// Mapped column of the .
+ /// Gets the reference that describes a column.
///
- [Serializable]
- public sealed class MappedColumn : Column
- {
- private const string ToStringFormat = "{0} = {1}";
-
- ///
- /// Gets the reference that describes a column.
- ///
- public ColumnInfoRef ColumnInfoRef { get; }
-
- ///
- public override string ToString()
- {
- return string.Format(ToStringFormat, base.ToString(), ColumnInfoRef);
- }
-
- ///
- public override Column Clone(ColNum newIndex)
- {
- return new MappedColumn(ColumnInfoRef, Name, newIndex, Type);
- }
+ public ColumnInfoRef ColumnInfoRef { get; } = columnInfoRef;
- ///
- public override Column Clone(string newName)
- {
- return new MappedColumn(this, newName);
- }
+ ///
+ public override string ToString() => $"{base.ToString()} = {ColumnInfoRef}";
- // Constructors
+ ///
+ public override Column Clone(ColNum newIndex) => new MappedColumn(ColumnInfoRef, Name, newIndex, Type);
- #region Basic constructors
+ ///
+ public override Column Clone(string newName) => new DerivedMappedColumn(newName, Index, Type, Origin, ColumnInfoRef);
- ///
- /// Initializes a new instance of this class.
- ///
- /// property value.
- /// property value.
- /// property value.
- public MappedColumn(string name, ColNum index, Type type)
- : this(default, name, index, type)
- {
- }
+ // Constructors
- ///
- /// Initializes a new instance of this class.
- ///
- /// property value.
- /// property value.
- /// property value.
- public MappedColumn(ColumnInfoRef columnInfoRef, ColNum index, Type type)
- : this(columnInfoRef, columnInfoRef.ColumnName, index, type)
- {
- }
+ #region Basic constructors
- ///
- /// Initializes a new instance of this class.
- ///
- /// property value.
- /// property value.
- /// property value.
- /// property value.
- public MappedColumn(ColumnInfoRef columnInfoRef, string name, ColNum index, Type type)
- : base(name, index, type, null)
- {
- ColumnInfoRef = columnInfoRef;
- }
-
- #endregion
+ ///
+ /// Initializes a new instance of this class.
+ ///
+ /// property value.
+ /// property value.
+ /// property value.
+ public MappedColumn(string name, ColNum index, Type type)
+ : this(default, name, index, type)
+ {
+ }
- #region Clone constructors
+ ///
+ /// Initializes a new instance of this class.
+ ///
+ /// property value.
+ /// property value.
+ /// property value.
+ public MappedColumn(ColumnInfoRef columnInfoRef, ColNum index, Type type)
+ : this(columnInfoRef, columnInfoRef.ColumnName, index, type)
+ {
+ }
- private MappedColumn(MappedColumn column, string newName)
- : base(newName, column.Index, column.Type, column)
- {
- ColumnInfoRef = column.ColumnInfoRef;
- }
+ #endregion
- private MappedColumn(MappedColumn column, ColNum newIndex)
- : base(column.Name, newIndex, column.Type, column)
- {
- ColumnInfoRef = column.ColumnInfoRef;
- }
+}
- #endregion
- }
+// The purpose of this class is minimize allocation size of `MappedColumn`
+// Non self-referencing `Origin` property is a rare case
+internal sealed class DerivedMappedColumn(string name, ColNum index, Type type, Column origin, ColumnInfoRef columnInfoRef)
+ : MappedColumn(columnInfoRef, name, index, type)
+{
+ public override Column Origin => origin ?? this;
}
diff --git a/Orm/Xtensive.Orm/Orm/Rse/SystemColumn.cs b/Orm/Xtensive.Orm/Orm/Rse/SystemColumn.cs
index fff250443..f7d8bffde 100644
--- a/Orm/Xtensive.Orm/Orm/Rse/SystemColumn.cs
+++ b/Orm/Xtensive.Orm/Orm/Rse/SystemColumn.cs
@@ -13,7 +13,7 @@ namespace Xtensive.Orm.Rse
/// System column of the .
///
[Serializable]
- public class SystemColumn : Column
+ public class SystemColumn : DerivedColumn
{
///
public override Column Clone(ColNum newIndex)
@@ -41,15 +41,15 @@ public SystemColumn(string name, ColNum index, Type type)
#region Clone constructors
private SystemColumn(SystemColumn column, ColNum newIndex)
- : base(column.Name, newIndex, column.Type, column)
+ : base(column.Name, newIndex, column.Type, column.Origin)
{
}
private SystemColumn(SystemColumn column, string newName)
- : base(newName, column.Index, column.Type, column)
+ : base(newName, column.Index, column.Type, column.Origin)
{
}
#endregion
}
-}
\ No newline at end of file
+}