You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/// <summary>/// Converts an ubiquitous enumeration of series to a strongly typed enumeration by matching property names./// </summary>/// <typeparam name="T">Type to convert the enumeration of series to</typeparam>/// <param name="series">Series to convert</param>/// <returns>Strongly typed enumeration representing the series</returns>publicstaticIEnumerable<T>As<T>(thisIEnumerable<Serie>series)whereT:new(){if(series==null)yieldreturndefault(T);Typetype=typeof(T);foreach(var serie in series){varproperties= type.GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();varmatchedProperties= serie.Columns
.Select(columnName => properties.FirstOrDefault(property => String.Compare(property.Name, columnName, StringComparison.InvariantCultureIgnoreCase)==0)).ToList();foreach(var value in serie.Values){varinstance=new T();for(varcolumnIndex=0;columnIndex< serie.Columns.Count();columnIndex++){varprop= matchedProperties[columnIndex];if(prop==null)continue;TypepropType= prop.PropertyType;varconvertedValue= Convert.ChangeType(value[columnIndex], prop.PropertyType);
prop.SetValue(instance, convertedValue);}yieldreturninstance;}}}
after
/// <summary>/// Converts an ubiquitous enumeration of series to a strongly typed enumeration by matching property names./// </summary>/// <typeparam name="T">Type to convert the enumeration of series to</typeparam>/// <param name="series">Series to convert</param>/// <returns>Strongly typed enumeration representing the series</returns>publicstaticIEnumerable<T>As<T>(thisIEnumerable<Serie>series)whereT:new(){if(series==null)yieldreturndefault(T);Typetype=typeof(T);foreach(var serie in series){varproperties= type.GetProperties(BindingFlags.Instance | BindingFlags.Public).ToList();varmatchedProperties= serie.Columns
.Select(columnName => properties.FirstOrDefault(property => String.Compare(property.Name, columnName, StringComparison.InvariantCultureIgnoreCase)==0)).ToList();foreach(var value in serie.Values){varinstance=new T();for(varcolumnIndex=0;columnIndex< serie.Columns.Count();columnIndex++){varprop= matchedProperties[columnIndex];if(prop==null)continue;TypepropType= prop.PropertyType;objectconvertedValue;if(propType.IsEnum){convertedValue= Enum.ToObject(propType, value[columnIndex]);}else{convertedValue= Convert.ChangeType(value[columnIndex], prop.PropertyType);}
prop.SetValue(instance, convertedValue);}yieldreturninstance;}}}
The text was updated successfully, but these errors were encountered:
before
after
The text was updated successfully, but these errors were encountered: