public static string GetSocketDomainName(SocketDomain domain) { var type = domain.GetType(); var memInfo = type.GetMember(domain.ToString()); if (memInfo != null && memInfo.Length > 0) { var attrs = memInfo[0].GetCustomAttributes(typeof(Output), false); if (attrs != null && attrs.Length > 0) { return(((Output)attrs[0]).Text); } } return(domain.ToString()); }
/// <summary>Преобразование к типу свойства</summary> /// <param name="domain">Домен свойства</param> /// <param name="value">Строковое значение</param> /// <returns>Значение свойства</returns> /// <exception cref="Exception">Тип не распознан</exception> private static object ParseProperty(SocketDomain domain, string value) { var type = SocketDomainType[domain]; if (type == typeof(string)) { return(value); } if (type == typeof(int)) { return(string.IsNullOrEmpty(value) ? -1 : int.Parse(value)); } if (type == typeof(float)) { return(string.IsNullOrEmpty(value) ? -1.0f : float.Parse(value, CultureInfo.InvariantCulture)); } throw new Exception("Type not recognized"); }