/// <summary> /// Returns the typed collection. /// </summary> /// <typeparam name="T">The type of each instance in the collection.</typeparam> /// <param name="creator">The instance factory.</param> /// <param name="propertyNames">The optional property names to map.</param> /// <returns>A typed collection based on the data parsed.</returns> public IEnumerable <T> ConvertTo <T>(Func <IReadOnlyList <string>, T> creator, IEnumerable <string> propertyNames = null) { var type = typeof(T); var props = propertyNames?.Select(ele => { try { if (!string.IsNullOrWhiteSpace(ele)) { return(type.GetProperty(ele)); } } catch (AmbiguousMatchException) { } return(null); })?.ToList(); if (props != null && props.Count == 0) { props = null; } if (creator == null && props == null) { yield break; } foreach (var item in this) { var instance = ObjectConvert.Invoke(item, creator, props); if (instance == null) { continue; } yield return(instance); } }
/// <summary> /// Synchronously gets the value of the specified column as a type. /// </summary> /// <typeparam name="TValue">Synchronously gets the value of the specified column as a type.</typeparam> /// <param name="ordinal">The zero-based column ordinal.</param> /// <returns>The value of the specified column.</returns> public override TValue GetFieldValue <TValue>(int ordinal) { return(ObjectConvert.Invoke <TValue>(this[ordinal])); }
/// <summary> /// Returns the typed collection. /// </summary> /// <typeparam name="T">The type of each instance in the collection.</typeparam> /// <param name="creator">The instance factory.</param> /// <param name="propertyNames">The property names to map.</param> /// <returns>A typed collection based on the data parsed.</returns> public T ConvertTo <T>(Func <IReadOnlyList <string>, T> creator, IEnumerable <string> propertyNames) { return(ObjectConvert.Invoke <T>(CurrentRecord, creator, propertyNames)); }
/// <summary> /// Returns the typed collection. /// </summary> /// <typeparam name="T">The type of each instance in the collection.</typeparam> /// <param name="creator">The instance factory.</param> /// <param name="propertyNames">The optional property names to map.</param> /// <returns>A typed collection based on the data parsed.</returns> public IEnumerable <T> ConvertTo <T>(Func <IReadOnlyList <string>, T> creator, IEnumerable <string> propertyNames = null) { var type = typeof(T); var props = propertyNames?.Select(ele => { try { if (!string.IsNullOrWhiteSpace(ele)) { return(type.GetProperty(ele)); } } catch (AmbiguousMatchException) { } return(null); })?.ToList(); if (props != null && props.Count == 0) { props = null; } if (creator == null) { if (props == null) { if (type == typeof(JsonArrayNode)) { foreach (var item in this) { var instance = new JsonArrayNode(); instance.AddRange(item); yield return((T)(object)instance); } } else if (type == typeof(System.Text.Json.Nodes.JsonArray)) { foreach (var item in this) { var instance = new System.Text.Json.Nodes.JsonArray(); foreach (var ele in item) { instance.Add(ele); } yield return((T)(object)instance); } } yield break; } else { if (type == typeof(JsonObjectNode)) { foreach (var item in this) { var instance = new JsonObjectNode(); instance.SetRange(item, propertyNames); yield return((T)(object)instance); } yield break; } } } foreach (var item in this) { var instance = ObjectConvert.Invoke(item, creator, props); if (instance == null) { continue; } yield return(instance); } }
/// <summary> /// Synchronously gets the value of the specified column as a type. /// </summary> /// <typeparam name="TValue">Synchronously gets the value of the specified column as a type.</typeparam> /// <param name="ordinal">The zero-based column ordinal.</param> /// <returns>The value of the specified column.</returns> public override TValue GetFieldValue <TValue>(int ordinal) => ObjectConvert.Invoke <TValue>(this[ordinal]);