Exemplo n.º 1
0
        public static string CombinePaths(params string[] paths)
        {
            var sb = StringBuilderThreadStatic.Allocate();

            AppendPaths(sb, paths);
            return(StringBuilderThreadStatic.ReturnAndFree(sb));
        }
Exemplo n.º 2
0
        public static string CombineWith(this string path, params object[] thesePaths)
        {
            if (thesePaths.Length == 1 && thesePaths[0] == null)
            {
                return(path);
            }

            var sb = StringBuilderThreadStatic.Allocate();

            sb.Append(path.TrimEnd('/', '\\'));
            AppendPaths(sb, ToStrings(thesePaths));
            return(StringBuilderThreadStatic.ReturnAndFree(sb));
        }
Exemplo n.º 3
0
        public static string AppendUrlPathsRaw(this string uri, params string[] uriComponents)
        {
            var sb = StringBuilderThreadStatic.Allocate();

            sb.Append(uri.WithTrailingSlash());
            var i = 0;

            foreach (var uriComponent in uriComponents)
            {
                if (i++ > 0)
                {
                    sb.Append('/');
                }
                sb.Append(uriComponent);
            }
            return(StringBuilderThreadStatic.ReturnAndFree(sb));
        }
Exemplo n.º 4
0
        public static Type GetCachedGenericType(this Type type, params Type[] argTypes)
        {
            if (!type.IsGenericTypeDefinition)
            {
                throw new ArgumentException(type.FullName + " is not a Generic Type Definition");
            }

            if (argTypes == null)
            {
                argTypes = Common.TypeConstants.EmptyTypeArray;
            }

            var sb = StringBuilderThreadStatic.Allocate()
                     .Append(type.FullName);

            foreach (var argType in argTypes)
            {
                sb.Append('|')
                .Append(argType.FullName);
            }

            var key = StringBuilderThreadStatic.ReturnAndFree(sb);

            if (_genericTypeCache.TryGetValue(key, out var genericType))
            {
                return(genericType);
            }

            genericType = type.MakeGenericType(argTypes);

            Dictionary <string, Type> snapshot, newCache;

            do
            {
                snapshot = _genericTypeCache;
                newCache = new Dictionary <string, Type>(_genericTypeCache)
                {
                    [key] = genericType
                };
            } while (!ReferenceEquals(
                         Interlocked.CompareExchange(ref _genericTypeCache, newCache, snapshot), snapshot));

            return(genericType);
        }
Exemplo n.º 5
0
        public static string CombineWith(this string path, params string[] thesePaths)
        {
            if (path == null)
            {
                path = "";
            }

            if (thesePaths.Length == 1 && thesePaths[0] == null)
            {
                return(path);
            }
            var startPath = path.Length > 1 ? path.TrimEnd('/', '\\') : path;

            var sb = StringBuilderThreadStatic.Allocate();

            sb.Append(startPath);
            AppendPaths(sb, thesePaths);
            return(StringBuilderThreadStatic.ReturnAndFree(sb));
        }
Exemplo n.º 6
0
        public static string ToPascalCase(this string value)
        {
            if (String.IsNullOrEmpty(value))
            {
                return(value);
            }

            if (value.IndexOf('_') >= 0)
            {
                var parts = value.Split('_');
                var sb    = StringBuilderThreadStatic.Allocate();
                foreach (var part in parts)
                {
                    var str = part.ToCamelCase();
                    sb.Append(char.ToUpper(str[0]) + str.SafeSubstring(1, str.Length));
                }
                return(StringBuilderThreadStatic.ReturnAndFree(sb));
            }

            var camelCase = value.ToCamelCase();

            return(char.ToUpper(camelCase[0]) + camelCase.SafeSubstring(1, camelCase.Length));
        }
Exemplo n.º 7
0
        public static string ToLowercaseUnderscore(this string value)
        {
            if (String.IsNullOrEmpty(value))
            {
                return(value);
            }
            value = value.ToCamelCase();

            var sb = StringBuilderThreadStatic.Allocate();

            foreach (char t in value)
            {
                if (char.IsDigit(t) || (char.IsLetter(t) && char.IsLower(t)) || t == '_')
                {
                    sb.Append(t);
                }
                else
                {
                    sb.Append("_");
                    sb.Append(char.ToLowerInvariant(t));
                }
            }
            return(StringBuilderThreadStatic.ReturnAndFree(sb));
        }