using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace Deltares.Stability.Calculation.Inner
{
///
/// Simple converter class to convert structures (struct) to dictionary (key value pairs)
///
internal static class StructToDictionaryHelper
{
///
/// Converts the target structure with public fields to a dictionary
///
///
/// The target to convert to a dictionary.
/// The dictionary with property names as key
public static IDictionary ToDictionary(this T target) where T : struct
{
FieldInfo[] fi = typeof(T).GetFields(BindingFlags.Public | BindingFlags.Instance);
return fi.ToDictionary(info => info.Name, info => info.GetValue(target));
}
}
}