File tree Expand file tree Collapse file tree 3 files changed +27
-11
lines changed
src/JsonApiDotNetCore/Models Expand file tree Collapse file tree 3 files changed +27
-11
lines changed Original file line number Diff line number Diff line change 1
- using System ;
1
+ using System . Reflection ;
2
2
3
3
namespace JsonApiDotNetCore . Models
4
4
{
@@ -9,5 +9,14 @@ public HasManyAttribute(string publicName)
9
9
{
10
10
PublicRelationshipName = publicName ;
11
11
}
12
+
13
+ public override void SetValue ( object entity , object newValue )
14
+ {
15
+ var propertyInfo = entity
16
+ . GetType ( )
17
+ . GetProperty ( InternalRelationshipName ) ;
18
+
19
+ propertyInfo . SetValue ( entity , newValue ) ;
20
+ }
12
21
}
13
22
}
Original file line number Diff line number Diff line change
1
+ using System . Reflection ;
2
+
1
3
namespace JsonApiDotNetCore . Models
2
4
{
3
5
public class HasOneAttribute : RelationshipAttribute
@@ -7,5 +9,18 @@ public HasOneAttribute(string publicName)
7
9
{
8
10
PublicRelationshipName = publicName ;
9
11
}
12
+
13
+ public override void SetValue ( object entity , object newValue )
14
+ {
15
+ var propertyName = ( newValue . GetType ( ) == Type )
16
+ ? InternalRelationshipName
17
+ : $ "{ InternalRelationshipName } Id";
18
+
19
+ var propertyInfo = entity
20
+ . GetType ( )
21
+ . GetProperty ( propertyName ) ;
22
+
23
+ propertyInfo . SetValue ( entity , newValue ) ;
24
+ }
10
25
}
11
26
}
Original file line number Diff line number Diff line change 1
1
using System ;
2
- using System . Reflection ;
3
2
4
3
namespace JsonApiDotNetCore . Models
5
4
{
6
- public class RelationshipAttribute : Attribute
5
+ public abstract class RelationshipAttribute : Attribute
7
6
{
8
7
protected RelationshipAttribute ( string publicName )
9
8
{
@@ -16,13 +15,6 @@ protected RelationshipAttribute(string publicName)
16
15
public bool IsHasMany { get { return this . GetType ( ) == typeof ( HasManyAttribute ) ; } }
17
16
public bool IsHasOne { get { return this . GetType ( ) == typeof ( HasOneAttribute ) ; } }
18
17
19
- public void SetValue ( object entity , object newValue )
20
- {
21
- var propertyInfo = entity
22
- . GetType ( )
23
- . GetProperty ( InternalRelationshipName ) ;
24
-
25
- propertyInfo . SetValue ( entity , newValue ) ;
26
- }
18
+ public abstract void SetValue ( object entity , object newValue ) ;
27
19
}
28
20
}
You can’t perform that action at this time.
0 commit comments