private static string GetEnumMemberName(FieldInfo member)
        {
            var attr1 = member.GetCustomAttribute <EnumMemberNameAttribute>();

            if (attr1 != null)
            {
                return(attr1.Name);
            }

            var attr2 = member.GetCustomAttribute <EnumMemberAttribute>();

            if (attr2 != null)
            {
                return(attr2.Value);
            }

            var name = member.Name;
            var sb   = LocalStringBuilderCache.New(name.Length + 5);

            for (var i = 0; i < name.Length; i++)
            {
                var c = name[i];
                if (i > 0 && char.IsUpper(c) && char.IsLower(name[i - 1]))
                {
                    sb.Append('_');
                }

                sb.Append(char.ToUpperInvariant(c));
            }
            return(LocalStringBuilderCache.GetStringAndRelease(sb));
        }
        private static string CustomStringFormat(string format, object[] args)
        {
            var builder = LocalStringBuilderCache.New(format.Length + (args?.Length ?? 0) * 5);

            CustomStringFormat(builder, format, args);
            return(LocalStringBuilderCache.GetStringAndRelease(builder));
        }
Exemple #3
0
        private static ILogMessage MakeCore(StringBuilder builder, ILogField[] fields)
        {
            if (fields != null && fields.Length > 0)
            {
                // Автоматическое добавление завершающей точки
                if (builder.Length > 0 && builder[builder.Length - 1] != '.')
                {
                    builder.Append('.');
                }

                // Автоматическое добавление завершающего пробела
                if (builder.Length > 0 && !char.IsWhiteSpace(builder[builder.Length - 1]))
                {
                    builder.Append(' ');
                }

                for (var i = 0; i < fields.Length; i++)
                {
                    builder.Append(fields[i].Print(PrintOption.Default));
                    if (i != fields.Length - 1)
                    {
                        builder.Append(", ");
                    }

                    (fields[i] as IReusable)?.Release();
                }
            }

            return(LogMessageImpl.Create(LocalStringBuilderCache.GetStringAndRelease(builder)));
        }
        private static string Normalize(string name)
        {
            var sb = LocalStringBuilderCache.New(name.Length);

            foreach (var c in name)
            {
                if (char.IsDigit(c) || char.IsUpper(c) || c == '_')
                {
                    sb.Append(c);
                }
                else if (char.IsLower(c))
                {
                    sb.Append(char.ToUpperInvariant(c));
                }
            }
            return(LocalStringBuilderCache.GetStringAndRelease(sb));
        }