Skip to content

Commit a7d1607

Browse files
author
Bart Koelman
committed
Looks like a left-over from entity-resource-separation, which no longer exists.
1 parent 57ad726 commit a7d1607

File tree

1 file changed

+7
-34
lines changed

1 file changed

+7
-34
lines changed

src/JsonApiDotNetCore/Models/Annotation/AttrAttribute.cs

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,12 @@ public object GetValue(object entity)
9595
throw new ArgumentNullException(nameof(entity));
9696
}
9797

98-
var property = GetResourceProperty(entity);
99-
if (property.GetMethod == null)
98+
if (PropertyInfo.GetMethod == null)
10099
{
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.");
102101
}
103102

104-
return property.GetValue(entity);
103+
return PropertyInfo.GetValue(entity);
105104
}
106105

107106
/// <summary>
@@ -114,40 +113,14 @@ public void SetValue(object entity, object newValue)
114113
throw new ArgumentNullException(nameof(entity));
115114
}
116115

117-
var property = GetResourceProperty(entity);
118-
if (property.SetMethod == null)
116+
if (PropertyInfo.SetMethod == null)
119117
{
120118
throw new InvalidOperationException(
121-
$"Property '{property.DeclaringType?.Name}.{property.Name}' is read-only.");
119+
$"Property '{PropertyInfo.DeclaringType?.Name}.{PropertyInfo.Name}' is read-only.");
122120
}
123121

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);
151124
}
152125

153126
/// <summary>

0 commit comments

Comments
 (0)