Пример #1
0
 public string GetProperty(string strPropertyName, string strFormat, System.Globalization.CultureInfo formatProvider, Entities.Users.UserInfo AccessingUser, Scope AccessLevel, ref bool PropertyNotFound)
 {
     if (obj == null)
     {
         return(string.Empty);
     }
     return(PropertyAccess.GetObjectProperty(obj, strPropertyName, strFormat, formatProvider, ref PropertyNotFound));
 }
Пример #2
0
        public static string GetObjectProperty(object objObject, string strPropertyName, string strFormat, System.Globalization.CultureInfo formatProvider, ref bool PropertyNotFound)
        {
            PropertyInfo objProperty = null;

            PropertyNotFound = false;
            if (CBO.GetProperties(objObject.GetType()).TryGetValue(strPropertyName, out objProperty))
            {
                object propValue = objProperty.GetValue(objObject, null);
                Type   t         = typeof(string);
                if (propValue != null)
                {
                    switch (objProperty.PropertyType.Name)
                    {
                    case "String":
                        return(FormatString(Convert.ToString(propValue), strFormat));

                    case "Boolean":
                        return(PropertyAccess.Boolean2LocalizedYesNo(Convert.ToBoolean(propValue), formatProvider));

                    case "DateTime":
                    case "Double":
                    case "Single":
                    case "Int32":
                    case "Int64":
                        if (strFormat == string.Empty)
                        {
                            strFormat = "g";
                        }
                        return(((IFormattable)propValue).ToString(strFormat, formatProvider));
                    }
                }
                else
                {
                    return("");
                }
            }
            PropertyNotFound = true;
            return(string.Empty);
        }