protected string StringByPiObject(PropertyInfo _pi, Object _O) { if (_O == null) { return(""); } if (Attribute.GetCustomAttribute(_pi, typeof(PasswordPropertyTextAttribute)) != null) { using (Cry cry = new Cry()) { string ret = cry.to(_O.ToString()); return(ret); } } if (_O is Color) { return(ColorTr.ToWin32((Color)_O)); } return(_O.ToString()); }
protected object GetValue(PropertyInfo _pi, string _path, string _sval) { if (_sval == null) { DefaultValueAttribute dva = Attribute.GetCustomAttribute(_pi, typeof(DefaultValueAttribute)) as DefaultValueAttribute; if (dva != null) { if (dva.Value == null) { if (_pi.PropertyType.IsGenericType && _pi.PropertyType.GetGenericTypeDefinition() == typeof(Nullable <>)) { return(null); } } return(Convert.ChangeType(dva.Value, _pi.PropertyType)); } } Type tp = _pi.PropertyType; if (tp == typeof(string)) { return(_sval); } if (tp == typeof(int)) { return(Convert.ToInt32(_sval)); } if (tp == typeof(int?)) { return(Convert.ToInt32(_sval)); } if (tp == typeof(uint)) { return(Convert.ToUInt32(_sval)); } if (tp == typeof(double)) { return(Convert.ToDouble(_sval, System.Globalization.CultureInfo.GetCultureInfo("ru-RU"))); } if (tp == typeof(float)) { return(Convert.ToSingle(_sval, System.Globalization.CultureInfo.GetCultureInfo("ru-RU"))); } if (tp == typeof(bool)) { return(_sval == "True"); } if (tp == typeof(short)) { return(Convert.ToInt16(_sval, System.Globalization.CultureInfo.GetCultureInfo("ru-RU"))); } if (tp == typeof(char)) { if (_sval == null) { return(' '); } return(_sval.Length == 0 ? ' ' : _sval[0]); } if (tp == typeof(Color)) { return(ColorTr.From(_sval)); } if (tp.BaseType == typeof(Enum)) { object eo = null; try { eo = Enum.Parse(tp, _sval); } catch { eo = null; } return(eo); } throw new InvalidOperationException("MetaPar.GetValue: Неопределенный тип: " + tp.ToString()); // FN.fatal("FN.ToDBString: Неопределенный тип: " + tp.ToString()); }