Skip to content
This repository was archived by the owner on Dec 1, 2021. It is now read-only.

Commit 3bf0bdf

Browse files
Suremakerdscottie
authored andcommitted
Exposed IConfiguration.GetMapping(string resourceType) (#19) (#21)
1 parent 8c33607 commit 3bf0bdf

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

src/NJsonApiCore/Configuration.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@ public IResourceMapping GetMapping(Type type)
5959
return mapping;
6060
}
6161

62+
public IResourceMapping GetMapping(string resourceType)
63+
{
64+
IResourceMapping mapping;
65+
resourcesMappingsByResourceType.TryGetValue(resourceType, out mapping);
66+
return mapping;
67+
}
68+
6269
public IResourceMapping GetMapping(object objectGraph)
6370
{
6471
return GetMapping(Reflection.GetObjectType(objectGraph));

src/NJsonApiCore/IConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
using Newtonsoft.Json;
22
using System;
3-
using System.Collections.Generic;
43

54
namespace NJsonApi
65
{
@@ -12,6 +11,8 @@ public interface IConfiguration
1211

1312
IResourceMapping GetMapping(Type type);
1413

14+
IResourceMapping GetMapping(string resourceType);
15+
1516
IResourceMapping GetMapping(object objectGraph);
1617

1718
JsonSerializer GetJsonSerializer();

test/NJsonApiCore.Test/Configuration/ConfigurationTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public void Creates_configuration_mapping()
2525
// Assert
2626
Assert.True(conf.IsResourceRegistered(typeof(Post)));
2727
Assert.NotNull(conf.GetMapping(typeof(Post)));
28+
Assert.NotNull(conf.GetMapping("posts"));
29+
2830
Assert.False(conf.IsResourceRegistered(typeof(Author)));
2931
Assert.Null(conf.GetMapping(typeof(Author)));
3032
}

0 commit comments

Comments
 (0)