Ejemplo n.º 1
0
        private static string InvariantToString(object obj)
        {
            if (Reflector.HasToString(obj))
            {
                var objStr = string.Format(CultureInfo.InvariantCulture, @"{0}", obj);
                var type   = obj.GetType();
                if (type == typeof(bool) || type == typeof(int))
                {
                    return(AuditLogParseHelper.GetParseString(ParseStringType.primitive, objStr));
                }
                else if (type == typeof(float) || type == typeof(double))
                {
                    return(AuditLogParseHelper.GetParseString(ParseStringType.primitive,
                                                              string.Format(CultureInfo.InvariantCulture, Program.FunctionalTest ? @"{0:G15}" : @"{0:R}",
                                                                            obj)));
                }
                else if (type.IsEnum)
                {
                    return(LogMessage.Quote(AuditLogParseHelper.GetParseString(ParseStringType.enum_fn, type.Name + '_' + objStr)));
                }
                return(LogMessage.Quote(objStr));
            }

            return(null);
        }
Ejemplo n.º 2
0
        private static string InvariantToString(object obj, int?decimalPlaces)
        {
            if (Reflector.HasToString(obj))
            {
                var objStr = string.Format(CultureInfo.InvariantCulture, @"{0}", obj);
                var type   = obj.GetType();
                if (type == typeof(bool) || type == typeof(int))
                {
                    return(AuditLogParseHelper.GetParseString(ParseStringType.primitive, objStr));
                }
                else if (type == typeof(float) || type == typeof(double))
                {
                    string format = @"R";
                    if (decimalPlaces.HasValue)
                    {
                        format = @"0." + new string('#', decimalPlaces.Value);
                    }

                    string replacementText = string.Format(@"{{0:{0}}}", format);
                    string decimalText     = string.Format(CultureInfo.InvariantCulture, replacementText, obj);

                    return(AuditLogParseHelper.GetParseString(ParseStringType.primitive, decimalText));
                }
                else if (type.IsEnum)
                {
                    return(LogMessage.Quote(AuditLogParseHelper.GetParseString(ParseStringType.enum_fn, type.Name + '_' + objStr)));
                }
                return(LogMessage.Quote(objStr));
            }

            return(null);
        }
Ejemplo n.º 3
0
        public static IAuditLogObject GetAuditLogObject(object obj, out bool usesReflection)
        {
            var auditLogObj = obj as IAuditLogObject;

            usesReflection = auditLogObj == null && !Reflector.HasToString(obj) &&
                             !AuditLogToStringHelper.IsKnownType(obj);
            return(auditLogObj ?? new AuditLogObject(obj));
        }
Ejemplo n.º 4
0
        public static IAuditLogObject GetAuditLogObject(object obj, int?decimalPlaces, out bool usesReflection)
        {
            var auditLogObj = obj as IAuditLogObject;

            usesReflection = auditLogObj == null && !Reflector.HasToString(obj) &&
                             !AuditLogToStringHelper.IsKnownType(obj);
            return(auditLogObj ?? new AuditLogObject(obj, decimalPlaces, SrmDocument.DOCUMENT_TYPE.none));
        }
Ejemplo n.º 5
0
        public static string InvariantToString(object obj)
        {
            if (Reflector.HasToString(obj))
            {
                var type   = obj.GetType();
                var format = "\"{0}\""; // Not L10N
                if (type == typeof(double) || type == typeof(bool) || type == typeof(int))
                {
                    format = "{{3:{0}}}"; // Not L10N
                }
                return(string.Format(CultureInfo.InvariantCulture, format, obj));
            }

            return(null);
        }