Skip to content

Commit 6d722ff

Browse files
committed
Merge pull request #929 from elasticsearch/fix/926
Remove class/interface validation when retrieving type from ElasticType
2 parents afe6ab3 + b68d955 commit 6d722ff

File tree

3 files changed

+40
-13
lines changed

3 files changed

+40
-13
lines changed

src/Nest/Resolvers/PropertyNameResolver.cs

-13
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,12 @@ public static IElasticPropertyAttribute Property(MemberInfo info)
3232
return null;
3333
}
3434

35-
public static ElasticTypeAttribute Type<T>() where T : class
36-
{
37-
return _Type(typeof(T));
38-
}
39-
4035
public static ElasticTypeAttribute Type(Type type)
41-
{
42-
return _Type(type);
43-
}
44-
45-
private static ElasticTypeAttribute _Type(Type type)
4636
{
4737
ElasticTypeAttribute attr = null;
4838
if (CachedTypeLookups.TryGetValue(type, out attr))
4939
return attr;
5040

51-
if (!type.IsClass && !type.IsInterface)
52-
throw new ArgumentException("Type is not a class or interface", "type");
53-
5441
var attributes = type.GetCustomAttributes(typeof(ElasticTypeAttribute), true);
5542
if (attributes.HasAny())
5643
attr = ((ElasticTypeAttribute)attributes.First());

src/Tests/Nest.Tests.Unit/Nest.Tests.Unit.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@
377377
<Compile Include="Reproduce\Reproduce860Tests.cs" />
378378
<Compile Include="Reproduce\Reproduce806Tests.cs" />
379379
<Compile Include="Reproduce\Reproduce876Tests.cs" />
380+
<Compile Include="Reproduce\Reproduce926Tests.cs" />
380381
<Compile Include="Search\Fields\FieldsTests.cs" />
381382
<Compile Include="Search\Filter\Modes\ConditionlessFilterJson.cs" />
382383
<Compile Include="Search\Filter\Modes\FilterModesTests.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using NUnit.Framework;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Nest.Tests.Unit.Reproduce
9+
{
10+
class SomeClass
11+
{
12+
public SomeClass()
13+
{
14+
this.Data = new Dictionary<long, SomeOtherClass>();
15+
}
16+
17+
public long ID { get; set; }
18+
19+
[ElasticProperty(Type = FieldType.Object)]
20+
public Dictionary<long, SomeOtherClass> Data { get; set; }
21+
}
22+
23+
class SomeOtherClass
24+
{
25+
public string Value1 { get; set; }
26+
public string Value2 { get; set; }
27+
}
28+
29+
[TestFixture]
30+
public class Reproduce926Tests : BaseJsonTests
31+
{
32+
[Test]
33+
public void ObjectMappingOnDictionaryCausesArgumentException()
34+
{
35+
var mapResult = this._client.Map<SomeClass>(m => m
36+
.MapFromAttributes());
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)