Пример #1
0
        private static string InternalGetValue(object o, PropertyInfo p, int index)
        {
            Type   propertyType = p.PropertyType;
            object obj1         = (object)null;

            if (propertyType.IsArray)
            {
                try
                {
                    object obj2       = p.GetValue(o, (object[])null);
                    int    lowerBound = ((Array)obj2).GetLowerBound(0);
                    int    upperBound = ((Array)obj2).GetUpperBound(0);
                    if (index <= lowerBound)
                    {
                        if (index <= upperBound)
                        {
                            obj1 = ((Array)obj2).GetValue(index);
                        }
                    }
                }
                catch
                {
                }
            }
            else
            {
                obj1 = p.GetValue(o, (object[])null);
            }
            string str = obj1 != null ? (!PropertyTest.IsNumeric(propertyType) ? (!PropertyTest.IsChar(propertyType) ? (!PropertyTest.IsString(propertyType) ? obj1.ToString() : string.Format("\"{0}\"", obj1)) : string.Format("'{0}' ({1} [0x{1:X}])", obj1, (object)(int)obj1)) : string.Format("{0} (0x{0:X})", obj1)) : "(-null-)";

            return(string.Format("{0} = {1}", (object)p.Name, (object)str));
        }
Пример #2
0
        private static string InternalGetValue(object o, PropertyInfo p, int index)
        {
            string str;
            Type   propertyType = p.PropertyType;
            object value        = null;

            if (!propertyType.IsArray)
            {
                value = p.GetValue(o, null);
            }
            else
            {
                try
                {
                    object obj        = p.GetValue(o, null);
                    int    lowerBound = ((Array)obj).GetLowerBound(0);
                    int    upperBound = ((Array)obj).GetUpperBound(0);
                    if (index <= lowerBound && index <= upperBound)
                    {
                        value = ((Array)obj).GetValue(index);
                    }
                }
                catch
                {
                }
            }
            if (value == null)
            {
                str = "(-null-)";
            }
            else if (PropertyTest.IsNumeric(propertyType))
            {
                str = string.Format("{0} (0x{0:X})", value);
            }
            else if (!PropertyTest.IsChar(propertyType))
            {
                str = (!PropertyTest.IsString(propertyType) ? value.ToString() : string.Format("\"{0}\"", value));
            }
            else
            {
                str = string.Format("'{0}' ({1} [0x{1:X}])", value, (int)value);
            }
            return(string.Format("{0} = {1}", p.Name, str));
        }