/// <summary> /// Maps the data row to a <see cref="ReflectionInfo" /> object. /// </summary> /// <param name="toReflect">The DataRow to map.</param> /// <returns> /// Returns an enumerable of <see cref="ReflectionInfo" /> objects, populated with data from the row /// </returns> public static ReflectionInfo FunnelDataRow(this DataRow toReflect) { var rInfo = new ReflectionInfo { SourceType = toReflect.GetType() }; for (int i = 0; i < toReflect.Table.Columns.Count; i++) { rInfo.Add(toReflect.Table.Columns[i].ColumnName, toReflect[i]); } return(rInfo); }
/// <summary> /// Iterates through the properties in an object and creates a Key / Value set to allow setting properties via reflection in another object. /// </summary> /// <param name="toReflect"> /// Object to reflect /// </param> /// <param name="bindingFlags"> /// BindingFlags in GetProperties Command Defaults to Public /// </param> /// <returns> /// ReflectionInfo Key / Value Set /// </returns> public static ReflectionInfo Funnel( this object toReflect, BindingFlags bindingFlags = DefaultBindings) { var reflectType = toReflect.GetType(); var props = reflectType.GetProperties(bindingFlags); var rInfo = new ReflectionInfo { SourceType = reflectType }; foreach (var prop in props) { rInfo.Add(prop.Name, prop.GetValue(toReflect, null)); } return(rInfo); }
/// <summary> /// Maps 2D Enumerable of paired values to a Key / Value to allow setting properties via reflection in another object. /// </summary> /// <typeparam name="TReflected"> /// Enumerable of Enumerable of value pairs /// </typeparam> /// <typeparam name="TKey"> /// The Property Name selector type /// </typeparam> /// <typeparam name="TValue"> /// The Value selector type /// </typeparam> /// <param name="toMap"> /// Enumerable of value pairs /// </param> /// <param name="keySelector"> /// Selector for Property Name /// </param> /// <param name="valueSelector"> /// Selector for Value /// </param> /// <returns> /// The Mapping.Extensions+ReflectionInfo. /// </returns> public static ReflectionInfo FunnelUsingSelector <TReflected, TKey, TValue>( this IEnumerable <TReflected> toMap, Func <TReflected, TKey> keySelector, Func <TReflected, TValue> valueSelector) { var reflectInfo = new ReflectionInfo { SourceType = typeof(TReflected) }; foreach (TReflected mapValue in toMap) { reflectInfo.Add(keySelector(mapValue), valueSelector(mapValue)); } return(reflectInfo); }