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 }
0 commit comments