private static IDictionary<string, string> GetParametersDictionary(IGeneralParameters parameters) { var beaconList = new BeaconList<string, string>(); foreach (var p in parameters.GetType().GetRuntimeProperties()) { var attr = p.GetCustomAttribute(typeof(BeaconAttribute), true) as BeaconAttribute; if (attr == null) continue; object value; if ((p.PropertyType.GetTypeInfo().IsEnum || p.PropertyType.IsNullableEnum()) && attr.IsEnumByValueBased) value = GetValueFromEnum(p, parameters) ?? p.GetMethod.Invoke(parameters, null); else if (p.PropertyType.GetTypeInfo().IsEnum || p.PropertyType.IsNullableEnum()) value = GetLowerCaseValueFromEnum(p, parameters) ?? p.GetMethod.Invoke(parameters, null); else value = p.GetMethod.Invoke(parameters, null); if (value != null) beaconList.Add(attr.Name, value.ToString()); } beaconList.ShiftToLast("z"); return beaconList.OrderBy(k => k.Item1, new BeaconComparer()).ToDictionary(key => key.Item1, value => value.Item2); }
private static IDictionary <string, string> GetParametersDictionary(IGeneralParameters parameters) { var beaconList = new BeaconList <string, string>(); foreach (var p in parameters.GetType().GetRuntimeProperties()) { var attr = p.GetCustomAttribute(typeof(BeaconAttribute), true) as BeaconAttribute; if (attr == null) { continue; } object value; var underlyingType = Nullable.GetUnderlyingType(p.PropertyType); if ((p.PropertyType.GetTypeInfo().IsEnum || p.PropertyType.IsNullableEnum()) && attr.IsEnumByValueBased) { value = GetValueFromEnum(p, parameters) ?? p.GetMethod.Invoke(parameters, null); } else if (p.PropertyType.GetTypeInfo().IsEnum || p.PropertyType.IsNullableEnum()) { value = GetLowerCaseValueFromEnum(p, parameters) ?? p.GetMethod.Invoke(parameters, null); } else if (p.PropertyType == typeof(bool) || (underlyingType != null && underlyingType == typeof(bool))) { value = p.GetMethod.Invoke(parameters, null); if (value != null) { value = (bool)value ? "1" : "0"; } } else { value = p.GetMethod.Invoke(parameters, null); } if (value == null) { continue; } beaconList.Add(attr.Name, Convert.ToString(value, CultureInfo.InvariantCulture)); } return(beaconList.ToDictionary(key => key.Item1, value => value.Item2)); }
private static IDictionary <string, string> GetParametersDictionary(IGeneralParameters parameters) { var beaconList = new BeaconList <string, string>(); foreach (var p in parameters.GetType().GetRuntimeProperties()) { var attr = p.GetCustomAttribute(typeof(BeaconAttribute), true) as BeaconAttribute; if (attr == null) { continue; } object value; if ((p.PropertyType.GetTypeInfo().IsEnum || p.PropertyType.IsNullableEnum()) && attr.IsEnumByValueBased) { value = GetValueFromEnum(p, parameters) ?? p.GetMethod.Invoke(parameters, null); } else if (p.PropertyType.GetTypeInfo().IsEnum || p.PropertyType.IsNullableEnum()) { value = GetLowerCaseValueFromEnum(p, parameters) ?? p.GetMethod.Invoke(parameters, null); } else { value = p.GetMethod.Invoke(parameters, null); } if (value != null) { beaconList.Add(attr.Name, value.ToString()); } } beaconList.ShiftToLast("z"); return(beaconList .OrderBy(k => k.Item1, new BeaconComparer()) .ToDictionary(key => key.Item1, value => value.Item2)); }