protected T HitToDocument <T>(IMultiGetHit <T> hit) where T : class, new() { if (hit.Found) { var doc = hit.Source; Type t = doc.GetType(); PropertyInfo piShared = t.GetProperty("id"); piShared.SetValue(doc, hit.Id); return(doc); } return(new T()); }
public static FindHit <T> ToFindHit <T>(this IMultiGetHit <T> hit) where T : class { var versionedDoc = hit.Source as IVersioned; if (versionedDoc != null && hit.Version != null) { versionedDoc.Version = Int64.Parse(hit.Version); } var data = new DataDictionary { { ElasticDataKeys.Index, hit.Index }, { ElasticDataKeys.IndexType, hit.Type } }; return(new FindHit <T>(hit.Id, hit.Source, 0, versionedDoc?.Version ?? null, data)); }
public static Hit <TTo> ToHit <TFrom, TTo>(this IMultiGetHit <TFrom> hit) where TFrom : class where TTo : class { // Validate parameters. if (hit == null) { throw new ArgumentNullException(nameof(hit)); } // Map and return. return(new Hit <TTo> { Item = hit.Source as TTo, Id = hit.Id, Index = hit.Index }); }