From 8b195936b1932cee1163fbd55a79c4e66f600b4e Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Thu, 29 Jun 2017 09:51:19 +1000 Subject: [PATCH] Add non-generic overload for As() Relates #2408 --- .../LazyDocument/LazyDocument.cs | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Nest/CommonAbstractions/LazyDocument/LazyDocument.cs b/src/Nest/CommonAbstractions/LazyDocument/LazyDocument.cs index 1d86961da3a..4331309e047 100644 --- a/src/Nest/CommonAbstractions/LazyDocument/LazyDocument.cs +++ b/src/Nest/CommonAbstractions/LazyDocument/LazyDocument.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using System; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; namespace Nest @@ -7,11 +8,18 @@ namespace Nest public interface ILazyDocument { /// - /// + /// Creates an instance of from this + /// instance /// - /// - /// + /// The type T As() where T : class; + + /// + /// Creates an instance of from this + /// instance + /// + /// The type + object As(Type objectType); } public class LazyDocument : ILazyDocument @@ -19,10 +27,18 @@ public class LazyDocument : ILazyDocument internal JToken _Value { get; set; } internal JsonSerializer _Serializer { get; set; } + /// public T As() where T : class { var jToken = this._Value; return jToken?.ToObject(_Serializer); } + + /// + public object As(Type objectType) + { + var jToken = this._Value; + return jToken?.ToObject(objectType, _Serializer); + } } }