@@ -95,13 +95,12 @@ public object GetValue(object entity)
95
95
throw new ArgumentNullException ( nameof ( entity ) ) ;
96
96
}
97
97
98
- var property = GetResourceProperty ( entity ) ;
99
- if ( property . GetMethod == null )
98
+ if ( PropertyInfo . GetMethod == null )
100
99
{
101
- throw new InvalidOperationException ( $ "Property '{ property . DeclaringType ? . Name } .{ property . Name } ' is write-only.") ;
100
+ throw new InvalidOperationException ( $ "Property '{ PropertyInfo . DeclaringType ? . Name } .{ PropertyInfo . Name } ' is write-only.") ;
102
101
}
103
102
104
- return property . GetValue ( entity ) ;
103
+ return PropertyInfo . GetValue ( entity ) ;
105
104
}
106
105
107
106
/// <summary>
@@ -114,40 +113,14 @@ public void SetValue(object entity, object newValue)
114
113
throw new ArgumentNullException ( nameof ( entity ) ) ;
115
114
}
116
115
117
- var property = GetResourceProperty ( entity ) ;
118
- if ( property . SetMethod == null )
116
+ if ( PropertyInfo . SetMethod == null )
119
117
{
120
118
throw new InvalidOperationException (
121
- $ "Property '{ property . DeclaringType ? . Name } .{ property . Name } ' is read-only.") ;
119
+ $ "Property '{ PropertyInfo . DeclaringType ? . Name } .{ PropertyInfo . Name } ' is read-only.") ;
122
120
}
123
121
124
- var convertedValue = TypeHelper . ConvertType ( newValue , property . PropertyType ) ;
125
- property . SetValue ( entity , convertedValue ) ;
126
- }
127
-
128
- private PropertyInfo GetResourceProperty ( object resource )
129
- {
130
- // There are some scenarios, especially ones where users are using a different
131
- // data model than view model, where they may use a repository implementation
132
- // that does not match the deserialized type. For now, we will continue to support
133
- // this use case.
134
- var targetType = resource . GetType ( ) ;
135
- if ( targetType != PropertyInfo . DeclaringType )
136
- {
137
- var propertyInfo = resource
138
- . GetType ( )
139
- . GetProperty ( PropertyInfo . Name ) ;
140
-
141
- return propertyInfo ;
142
-
143
- // TODO: this should throw but will be a breaking change in some cases
144
- //if (propertyInfo == null)
145
- // throw new InvalidOperationException(
146
- // $"'{targetType}' does not contain a member named '{InternalAttributeName}'." +
147
- // $"There is also a mismatch in target types. Expected '{PropertyInfo.DeclaringType}' but instead received '{targetType}'.");
148
- }
149
-
150
- return PropertyInfo ;
122
+ var convertedValue = TypeHelper . ConvertType ( newValue , PropertyInfo . PropertyType ) ;
123
+ PropertyInfo . SetValue ( entity , convertedValue ) ;
151
124
}
152
125
153
126
/// <summary>
0 commit comments