Skip to content

Commit 8b19593

Browse files
committed
Add non-generic overload for As()
Relates #2408
1 parent 042b319 commit 8b19593

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed
Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using Newtonsoft.Json;
1+
using System;
2+
using Newtonsoft.Json;
23
using Newtonsoft.Json.Linq;
34

45
namespace Nest
@@ -7,22 +8,37 @@ namespace Nest
78
public interface ILazyDocument
89
{
910
/// <summary>
10-
///
11+
/// Creates an instance of <typeparamref name="T"/> from this
12+
/// <see cref="ILazyDocument"/> instance
1113
/// </summary>
12-
/// <typeparam name="T"></typeparam>
13-
/// <returns></returns>
14+
/// <typeparam name="T">The type</typeparam>
1415
T As<T>() where T : class;
16+
17+
/// <summary>
18+
/// Creates an instance of <paramref name="objectType"/> from this
19+
/// <see cref="ILazyDocument"/> instance
20+
/// </summary>
21+
/// <typeparam name="T">The type</typeparam>
22+
object As(Type objectType);
1523
}
1624

1725
public class LazyDocument : ILazyDocument
1826
{
1927
internal JToken _Value { get; set; }
2028
internal JsonSerializer _Serializer { get; set; }
2129

30+
/// <inheritdoc />
2231
public T As<T>() where T : class
2332
{
2433
var jToken = this._Value;
2534
return jToken?.ToObject<T>(_Serializer);
2635
}
36+
37+
/// <inheritdoc />
38+
public object As(Type objectType)
39+
{
40+
var jToken = this._Value;
41+
return jToken?.ToObject(objectType, _Serializer);
42+
}
2743
}
2844
}

0 commit comments

Comments
 (0)