Skip to content

Commit b866e36

Browse files
authored
Merge pull request #381 from DataObjects-NET/master-upgradehints-imps
Improves upgrade hints, mostly user experience
2 parents e0646c2 + a417681 commit b866e36

10 files changed

Lines changed: 196 additions & 262 deletions

File tree

ChangeLog/7.2.0-Beta-2-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[main] Upgrade hints change names of constructors' string parameters for better understanding of what suppose to be in them.

Orm/Xtensive.Orm/Orm/Upgrade/Hints/ChangeFieldTypeHint.cs

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2009-2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Ivan Galkin
55
// Created: 2009.06.05
66

@@ -19,8 +19,6 @@ namespace Xtensive.Orm.Upgrade
1919
public sealed class ChangeFieldTypeHint : UpgradeHint,
2020
IEquatable<ChangeFieldTypeHint>
2121
{
22-
private const string ToStringFormat = "Change type of field: {0}.{1}";
23-
2422
/// <summary>
2523
/// Gets the target type.
2624
/// </summary>
@@ -45,45 +43,39 @@ public bool Equals(ChangeFieldTypeHint other)
4543
return true;
4644
var comparer = StringComparer.OrdinalIgnoreCase;
4745
return base.Equals(other)
48-
&& other.Type==Type
46+
&& other.Type == Type
4947
&& comparer.Equals(other.FieldName, FieldName);
5048
}
5149

5250
/// <inheritdoc/>
53-
public override bool Equals(UpgradeHint other)
54-
{
55-
return Equals(other as ChangeFieldTypeHint);
56-
}
51+
public override bool Equals(UpgradeHint other) => Equals(other as ChangeFieldTypeHint);
5752

5853
/// <inheritdoc/>
5954
public override int GetHashCode()
6055
{
6156
unchecked {
6257
int result = base.GetHashCode();
63-
result = (result * 397) ^ (Type!=null ? Type.GetHashCode() : 0);
64-
result = (result * 397) ^ (FieldName!=null ? FieldName.GetHashCode() : 0);
58+
result = (result * 397) ^ (Type != null ? Type.GetHashCode() : 0);
59+
result = (result * 397) ^ (FieldName != null ? FieldName.GetHashCode() : 0);
6560
return result;
6661
}
6762
}
6863

6964
/// <inheritdoc/>
70-
public override string ToString()
71-
{
72-
return string.Format(ToStringFormat, Type, FieldName);
73-
}
65+
public override string ToString() => $"Change type of field: {Type}.{FieldName}";
7466

7567

7668
// Constructors
7769

7870
/// <summary>
7971
/// Initializes a new instance of this class.
8072
/// </summary>
81-
/// <param name="type">Value for <see cref="Type"/>.</param>
82-
/// <param name="fieldName">Value for <see cref="FieldName"/>.</param>
73+
/// <param name="type">The type field belongs to.</param>
74+
/// <param name="fieldName">Name of field that changes type.</param>
8375
public ChangeFieldTypeHint(Type type, string fieldName)
8476
{
85-
ArgumentValidator.EnsureArgumentNotNull(type, "type");
86-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(fieldName, "sourceField");
77+
ArgumentValidator.EnsureArgumentNotNull(type, nameof(type));
78+
ArgumentValidator.EnsureArgumentNotNullOrEmpty(fieldName, nameof(fieldName));
8779

8880
Type = type;
8981
FieldName = fieldName;

Orm/Xtensive.Orm/Orm/Upgrade/Hints/CopyFieldHint.cs

Lines changed: 55 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2009-2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Denis Kryuchkov
55
// Created: 2009.05.29
66

@@ -19,8 +19,6 @@ namespace Xtensive.Orm.Upgrade
1919
public class CopyFieldHint : UpgradeHint,
2020
IEquatable<CopyFieldHint>
2121
{
22-
private const string ToStringFormat = "Copy field: {0}.{1} -> {2}.{3}";
23-
2422
/// <summary>
2523
/// Gets the source type.
2624
/// </summary>
@@ -48,100 +46,94 @@ public bool Equals(CopyFieldHint other)
4846
return false;
4947
if (ReferenceEquals(this, other))
5048
return true;
51-
return base.Equals(other)
52-
&& other.SourceType==SourceType
53-
&& other.SourceField==SourceField
54-
&& other.TargetType==TargetType
55-
&& other.TargetField==TargetField;
49+
return base.Equals(other)
50+
&& other.SourceType == SourceType
51+
&& other.SourceField == SourceField
52+
&& other.TargetType == TargetType
53+
&& other.TargetField == TargetField;
5654
}
5755

5856
/// <inheritdoc/>
59-
public override bool Equals(UpgradeHint other)
60-
{
61-
return Equals(other as CopyFieldHint);
62-
}
57+
public override bool Equals(UpgradeHint other) => Equals(other as CopyFieldHint);
6358

6459
/// <inheritdoc/>
6560
public override int GetHashCode()
6661
{
6762
unchecked {
6863
int result = base.GetHashCode();
69-
result = (result * 397) ^ (SourceType!=null ? SourceType.GetHashCode() : 0);
70-
result = (result * 397) ^ (SourceField!=null ? SourceField.GetHashCode() : 0);
71-
result = (result * 397) ^ (TargetType!=null ? TargetType.GetHashCode() : 0);
72-
result = (result * 397) ^ (TargetField!=null ? TargetField.GetHashCode() : 0);
64+
result = (result * 397) ^ (SourceType != null ? SourceType.GetHashCode() : 0);
65+
result = (result * 397) ^ (SourceField != null ? SourceField.GetHashCode() : 0);
66+
result = (result * 397) ^ (TargetType != null ? TargetType.GetHashCode() : 0);
67+
result = (result * 397) ^ (TargetField != null ? TargetField.GetHashCode() : 0);
7368
return result;
7469
}
7570
}
7671

7772
/// <inheritdoc/>
78-
public override string ToString()
79-
{
80-
return string.Format(ToStringFormat,
81-
SourceType, SourceField, TargetType.GetFullName(), TargetField);
82-
}
73+
public override string ToString() =>
74+
$"Copy field: {SourceType}.{SourceField} -> {TargetType.GetFullName()}.{TargetField}";
8375

8476

8577
// Constructors
8678

8779
/// <summary>
8880
/// Initializes a new instance of this class.
8981
/// </summary>
90-
/// <param name="sourceType">Value for <see cref="SourceType"/>.</param>
91-
/// <param name="sourceField">Value for <see cref="SourceField"/>.</param>
92-
/// <param name="targetType">Value for <see cref="TargetType"/>.</param>
93-
/// <param name="targetField">Value for <see cref="TargetField"/>.</param>
94-
public CopyFieldHint(string sourceType, string sourceField, Type targetType, string targetField)
82+
/// <param name="sourceTypeName">The source type full name.</param>
83+
/// <param name="sourceFieldName">Name of source field.</param>
84+
/// <param name="targetType">The target type.</param>
85+
/// <param name="targetFieldName">Name of target field.</param>
86+
public CopyFieldHint(string sourceTypeName, string sourceFieldName, Type targetType, string targetFieldName)
9587
{
96-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceType, "sourceType");
97-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceField, "sourceField");
98-
ArgumentValidator.EnsureArgumentNotNull(targetType, "targetType");
99-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(targetField, "targetField");
100-
SourceType = sourceType;
101-
SourceField = sourceField;
88+
ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceTypeName, nameof(sourceTypeName));
89+
ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceFieldName, nameof(sourceFieldName));
90+
ArgumentValidator.EnsureArgumentNotNull(targetType, nameof(targetType));
91+
ArgumentValidator.EnsureArgumentNotNullOrEmpty(targetFieldName, nameof(targetFieldName));
92+
SourceType = sourceTypeName;
93+
SourceField = sourceFieldName;
10294
TargetType = targetType;
103-
TargetField = targetField;
95+
TargetField = targetFieldName;
10496
}
10597

10698
/// <summary>
10799
/// Initializes a new instance of this class.
108100
/// </summary>
109-
/// <param name="sourceType">Value for <see cref="SourceType"/>.</param>
110-
/// <param name="field">Value for <see cref="SourceField"/> and <see cref="TargetField"/>.</param>
111-
/// <param name="targetType">Value for <see cref="TargetType"/>.</param>
112-
public CopyFieldHint(Type sourceType, string field, Type targetType)
113-
: this(sourceType, field, targetType, field)
101+
/// <param name="sourceType">The source type.</param>
102+
/// <param name="fieldName">Name of field in both source and target types.</param>
103+
/// <param name="targetType">The target type.</param>
104+
public CopyFieldHint(Type sourceType, string fieldName, Type targetType)
105+
: this(sourceType, fieldName, targetType, fieldName)
114106
{
115107
}
116108

117109
/// <summary>
118110
/// Initializes a new instance of this class.
119111
/// </summary>
120-
/// <param name="sourceType">Value for <see cref="SourceType"/>.</param>
121-
/// <param name="sourceField">Value for <see cref="SourceField"/>.</param>
122-
/// <param name="targetType">Value for <see cref="TargetType"/>.</param>
123-
/// <param name="targetField">Value for <see cref="TargetField"/>.</param>
124-
public CopyFieldHint(Type sourceType, string sourceField, Type targetType, string targetField)
112+
/// <param name="sourceType">The source type.</param>
113+
/// <param name="sourceFieldName">The source field name.</param>
114+
/// <param name="targetType">The target type name.</param>
115+
/// <param name="targetFieldName">The target field name.</param>
116+
public CopyFieldHint(Type sourceType, string sourceFieldName, Type targetType, string targetFieldName)
125117
{
126-
ArgumentValidator.EnsureArgumentNotNull(sourceType, "sourceType");
127-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceField, "sourceField");
128-
ArgumentValidator.EnsureArgumentNotNull(targetType, "targetType");
129-
ArgumentValidator.EnsureArgumentNotNullOrEmpty(targetField, "targetField");
118+
ArgumentValidator.EnsureArgumentNotNull(sourceType, nameof(sourceType));
119+
ArgumentValidator.EnsureArgumentNotNullOrEmpty(sourceFieldName, nameof(sourceFieldName));
120+
ArgumentValidator.EnsureArgumentNotNull(targetType, nameof(targetType));
121+
ArgumentValidator.EnsureArgumentNotNullOrEmpty(targetFieldName, nameof(targetFieldName));
130122

131123
SourceType = sourceType.FullName;
132-
SourceField = sourceField;
124+
SourceField = sourceFieldName;
133125
TargetType = targetType;
134-
TargetField = targetField;
126+
TargetField = targetFieldName;
135127
}
136128

137129
/// <summary>
138130
/// Initializes a new instance of this class.
139131
/// </summary>
140-
/// <param name="sourceType">Value for <see cref="SourceType"/>.</param>
141-
/// <param name="field">Value for <see cref="SourceField"/> and <see cref="TargetField"/>.</param>
142-
/// <param name="targetType">Value for <see cref="TargetType"/>.</param>
143-
public CopyFieldHint(string sourceType, string field, Type targetType)
144-
: this(sourceType, field, targetType, field)
132+
/// <param name="sourceTypeName">The source type full name.</param>
133+
/// <param name="fieldName">Field name in both source and target types.</param>
134+
/// <param name="targetType">The target type.</param>
135+
public CopyFieldHint(string sourceTypeName, string fieldName, Type targetType)
136+
: this(sourceTypeName, fieldName, targetType, fieldName)
145137
{
146138
}
147139

@@ -168,35 +160,35 @@ public static CopyFieldHint Create<TSource, TTarget>(
168160
/// Creates the instance of this hint.
169161
/// </summary>
170162
/// <typeparam name="TTarget">The target type.</typeparam>
171-
/// <param name="sourceType">The source type.</param>
172-
/// <param name="sourceField">The source field.</param>
163+
/// <param name="sourceTypeName">Full name of source type.</param>
164+
/// <param name="sourceFieldName">The source field name.</param>
173165
/// <param name="targetPropertyAccessExpression">The target field access expression.</param>
174166
/// <returns>The newly created instance of this hint.</returns>
175167
public static CopyFieldHint Create<TTarget>(
176-
string sourceType, string sourceField,
168+
string sourceTypeName, string sourceFieldName,
177169
Expression<Func<TTarget, object>> targetPropertyAccessExpression)
178170
where TTarget: Entity
179171
{
180172
return new CopyFieldHint(
181-
sourceType, sourceField,
173+
sourceTypeName, sourceFieldName,
182174
typeof(TTarget), targetPropertyAccessExpression.GetProperty().Name);
183175
}
184176

185177
/// <summary>
186178
/// Creates the instance of this hint.
187179
/// </summary>
188180
/// <typeparam name="TTarget">The target type.</typeparam>
189-
/// <param name="sourceType">The source type.</param>
181+
/// <param name="sourceTypeName">Full name of source type.</param>
190182
/// <param name="targetPropertyAccessExpression">The target field access expression.</param>
191183
/// <returns>The newly created instance of this hint.</returns>
192184
public static CopyFieldHint Create<TTarget>(
193-
string sourceType,
185+
string sourceTypeName,
194186
Expression<Func<TTarget, object>> targetPropertyAccessExpression)
195187
where TTarget: Entity
196188
{
197189
var targetField = targetPropertyAccessExpression.GetProperty().Name;
198190
return new CopyFieldHint(
199-
sourceType, targetField,
191+
sourceTypeName, targetField,
200192
typeof(TTarget), targetField);
201193
}
202194
}

Orm/Xtensive.Orm/Orm/Upgrade/Hints/MergeTypeHint.cs

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// Copyright (C) 2003-2010 Xtensive LLC.
2-
// All rights reserved.
3-
// For conditions of distribution and use, see license.
1+
// Copyright (C) 2009-2024 Xtensive LLC.
2+
// This code is distributed under MIT license terms.
3+
// See the License.txt file in the project root for more information.
44
// Created by: Alex Kofman
55
// Created: 2009.04.29
66

@@ -20,8 +20,6 @@ namespace Xtensive.Orm.Upgrade
2020
public sealed class MergeTypeHint : UpgradeHint,
2121
IEquatable<MergeTypeHint>
2222
{
23-
private const string ToStringFormat = "Merge type: {0} -> {1}";
24-
2523
/// <summary>
2624
/// Gets the new type.
2725
/// </summary>
@@ -39,33 +37,28 @@ public bool Equals(MergeTypeHint other)
3937
return false;
4038
if (ReferenceEquals(this, other))
4139
return true;
42-
return base.Equals(other)
43-
&& other.NewType==NewType
44-
&& other.OldType==OldType;
40+
return base.Equals(other)
41+
&& other.NewType == NewType
42+
&& other.OldType == OldType;
4543
}
4644

4745
/// <inheritdoc/>
48-
public override bool Equals(UpgradeHint other)
49-
{
50-
return Equals(other as MergeTypeHint);
51-
}
46+
public override bool Equals(UpgradeHint other) => Equals(other as MergeTypeHint);
5247

5348
/// <inheritdoc/>
5449
public override int GetHashCode()
5550
{
5651
unchecked {
5752
int result = base.GetHashCode();
58-
result = (result * 397) ^ (NewType!=null ? NewType.GetHashCode() : 0);
59-
result = (result * 397) ^ (OldType!=null ? OldType.GetHashCode() : 0);
53+
result = (result * 397) ^ (NewType != null ? NewType.GetHashCode() : 0);
54+
result = (result * 397) ^ (OldType != null ? OldType.GetHashCode() : 0);
6055
return result;
6156
}
6257
}
6358

6459
/// <inheritdoc/>
65-
public override string ToString()
66-
{
67-
return string.Format(ToStringFormat, OldType.GetFullName(), NewType.GetFullName());
68-
}
60+
public override string ToString() =>
61+
$"Merge type: {OldType.GetFullName()} -> {NewType.GetFullName()}";
6962

7063

7164
// Constructors
@@ -77,8 +70,8 @@ public override string ToString()
7770
/// <param name="newType">The new type.</param>
7871
public MergeTypeHint(Type oldType, Type newType)
7972
{
80-
ArgumentValidator.EnsureArgumentNotNull(newType, "newType");
81-
ArgumentValidator.EnsureArgumentNotNull(oldType, "oldType");
73+
ArgumentValidator.EnsureArgumentNotNull(newType, nameof(newType));
74+
ArgumentValidator.EnsureArgumentNotNull(oldType, nameof(oldType));
8275

8376
OldType = oldType;
8477
NewType = newType;

0 commit comments

Comments
 (0)