Esempio n. 1
0
 private static string ValueAsString(object value, Type type = null)
 {
     if (type == null)
     {
         type = value?.GetType() ?? typeof(object);
     }
     if (value == null)
     {
         return("null");
     }
     if (value is bool)
     {
         return(value.ToString().ToLower());
     }
     if (value is IntPtr)
     {
         return($"0x{((IntPtr) value).ToInt64():X}");
     }
     if (value is string)
     {
         return($"{AstStringUtils.ToLiteral(value as string)}");
     }
     if (AstUtils.IsTypeSigned(type))
     {
         return(value.ToString());
     }
     if (Convert.ToInt64(value) > 9)
     {
         return($"0x{value:X}");
     }
     return(value.ToString());
 }
Esempio n. 2
0
        private String ValueAsString(object Value, Type Type = null)
        {
            if (Type == null)
            {
                Type = (Value != null) ? Value.GetType() : typeof(Object);
            }
            if (Value == null)
            {
                return("null");
            }

            if (Value is bool)
            {
                return(Value.ToString().ToLower());
            }
            else if (Value is IntPtr)
            {
                return(String.Format("0x{0:X}", ((IntPtr)Value).ToInt64()));
            }
            else if (Value is string)
            {
                return(String.Format("{0}", AstStringUtils.ToLiteral(Value as string)));
            }
            else if (!AstUtils.IsTypeSigned(Type))
            {
                //StringValue = String.Format("0x{0:X8}", ItemValue);
                if (Convert.ToInt64(Value) > 9)
                {
                    return(String.Format("0x{0:X}", Value));
                }
            }

            return(Value.ToString());
        }