Ejemplo n.º 1
0
        internal static string FormatLiteral(char c, ObjectDisplayOptions options)
        {
            const char quote = '\'';

            var pooledBuilder = PooledStringBuilder.GetInstance();
            var builder       = pooledBuilder.Builder;

            if (options.IncludesOption(ObjectDisplayOptions.IncludeCodePoints))
            {
                builder.Append(options.IncludesOption(ObjectDisplayOptions.UseHexadecimalNumbers) ? "0x" + ((int)c).ToString("x4") : ((int)c).ToString());
                builder.Append(" ");
            }

            var useQuotes          = options.IncludesOption(ObjectDisplayOptions.UseQuotes);
            var escapeNonPrintable = options.IncludesOption(ObjectDisplayOptions.EscapeNonPrintableCharacters);

            if (useQuotes)
            {
                builder.Append(quote);
            }

            string replaceWith;

            if (escapeNonPrintable && TryReplaceChar(c, out replaceWith))
            {
                builder.Append(replaceWith);
            }
            else if (useQuotes && c == quote)
            {
                builder.Append('\\');
                builder.Append(quote);
            }
            else
            {
                builder.Append(c);
            }

            if (useQuotes)
            {
                builder.Append(quote);
            }

            return(pooledBuilder.ToStringAndFree());
        }
Ejemplo n.º 2
0
        internal string GetTypeName(
            TypeAndCustomInfo typeAndInfo,
            bool escapeKeywordIdentifiers,
            out bool sawInvalidIdentifier
            )
        {
            var type = typeAndInfo.Type;

            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            ReadOnlyCollection <byte>   dynamicFlags      = null;
            ReadOnlyCollection <string> tupleElementNames = null;
            var typeInfo = typeAndInfo.Info;

            if (typeInfo != null)
            {
                CustomTypeInfo.Decode(
                    typeInfo.PayloadTypeId,
                    typeInfo.Payload,
                    out dynamicFlags,
                    out tupleElementNames
                    );
            }

            var dynamicFlagIndex  = 0;
            var tupleElementIndex = 0;
            var pooled            = PooledStringBuilder.GetInstance();

            AppendQualifiedTypeName(
                pooled.Builder,
                type,
                dynamicFlags,
                ref dynamicFlagIndex,
                tupleElementNames,
                ref tupleElementIndex,
                escapeKeywordIdentifiers,
                out sawInvalidIdentifier
                );
            return(pooled.ToStringAndFree());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a Lua string literal with the given value.
        /// </summary>
        /// <param name="value">The value that the resulting string literal should have.</param>
        /// <param name="options">Options used to customize formatting of an object value.</param>
        /// <returns>A string literal with the given value.</returns>
        /// <remarks>
        /// Optionally escapes non-printable characters.
        /// </remarks>
        public static string FormatLiteral(string value, ObjectDisplayOptions options)
        {
            const char shortStringQuote = '"';

            if (value is null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            var pooledBuilder = PooledStringBuilder.GetInstance();
            var builder       = pooledBuilder.Builder;

            var useQuotes          = options.IncludesOption(ObjectDisplayOptions.UseQuotes);
            var escapeNonPrintable = options.IncludesOption(ObjectDisplayOptions.EscapeNonPrintableCharacters);
            var utf8Escape         = options.IncludesOption(ObjectDisplayOptions.EscapeWithUtf8);

            var isVerbatim = useQuotes && !escapeNonPrintable && ContainsNewLine(value);

            string endDelimiter = "";

            if (useQuotes)
            {
                if (isVerbatim)
                {
                    if (!TryFastGetVerbatimEquals(value.AsSpan(), out var startDelimiter, out endDelimiter !))
                    {
                        (startDelimiter, endDelimiter) = SlowGetVerbatimEquals(value);
                    }
                    builder.Append(startDelimiter);
                }
                else
                {
                    endDelimiter = shortStringQuote.ToString();
                }
            }

            for (var idx = 0; idx < value.Length; idx++)
            {
                var ch = value[idx];
                if (escapeNonPrintable && TryReplaceChar(ch, out var replaceWith, utf8Escape))
                {
                    builder.Append(replaceWith);
                }
Ejemplo n.º 4
0
        public override string FormatException(Exception e)
        {
            if (e == null)
            {
                throw new ArgumentNullException(nameof(e));
            }

            var pooled  = PooledStringBuilder.GetInstance();
            var builder = pooled.Builder;

            builder.AppendLine(e.Message);

            var trace = new StackTrace(e, needFileInfo: true);

            foreach (var frame in trace.GetFrames())
            {
                if (!Filter.Include(frame))
                {
                    continue;
                }

                var method        = frame.GetMethod();
                var methodDisplay = FormatMethodSignature(method);

                if (methodDisplay == null)
                {
                    continue;
                }

                builder.Append("  + ");
                builder.Append(methodDisplay);

                var fileName = frame.GetFileName();
                if (fileName != null)
                {
                    builder.Append(string.Format(CultureInfo.CurrentUICulture, ScriptingResources.AtFileLine, fileName, frame.GetFileLineNumber()));
                }

                builder.AppendLine();
            }

            return(pooled.ToStringAndFree());
        }
Ejemplo n.º 5
0
        public static CompletionItem Create(string name, int arity, string containingNamespace, Glyph glyph, string genericTypeSuffix, CompletionItemFlags flags, string?symbolKeyData)
        {
            ImmutableDictionary <string, string>?properties = null;

            if (symbolKeyData != null || arity > 0)
            {
                var builder = PooledDictionary <string, string> .GetInstance();

                if (symbolKeyData != null)
                {
                    builder.Add(SymbolKeyData, symbolKeyData);
                }
                else
                {
                    // We don't need arity to recover symbol if we already have SymbolKeyData or it's 0.
                    // (but it still needed below to decide whether to show generic suffix)
                    builder.Add(TypeAritySuffixName, AbstractDeclaredSymbolInfoFactoryService.GetMetadataAritySuffix(arity));
                }

                properties = builder.ToImmutableDictionaryAndFree();
            }

            // Add tildes (ASCII: 126) to name and namespace as sort text:
            // 1. '~' before type name makes import items show after in-scope items
            // 2. ' ' before namespace makes types with identical type name but from different namespace all show up in the list,
            //    it also makes sure type with shorter name shows first, e.g. 'SomeType` before 'SomeTypeWithLongerName'.
            var sortTextBuilder = PooledStringBuilder.GetInstance();

            sortTextBuilder.Builder.AppendFormat(SortTextFormat, name, containingNamespace);

            var item = CompletionItem.Create(
                displayText: name,
                sortText: sortTextBuilder.ToStringAndFree(),
                properties: properties,
                tags: GlyphTags.GetTags(glyph),
                rules: CompletionItemRules.Default,
                displayTextPrefix: null,
                displayTextSuffix: arity == 0 ? string.Empty : genericTypeSuffix,
                inlineDescription: containingNamespace);

            item.Flags = flags;
            return(item);
        }
Ejemplo n.º 6
0
        internal static string MakeHoistedLocalFieldName(SynthesizedLocalKind kind, int slotIndex, string?localName = null)
        {
            Debug.Assert((localName != null) == (kind == SynthesizedLocalKind.UserDefined));
            Debug.Assert(slotIndex >= 0);
            Debug.Assert(kind.IsLongLived());

            // Lambda display class local follows a different naming pattern.
            // EE depends on the name format.
            // There's logic in the EE to recognize locals that have been captured by a lambda
            // and would have been hoisted for the state machine.  Basically, we just hoist the local containing
            // the instance of the lambda display class and retain its original name (rather than using an
            // iterator local name).  See FUNCBRECEE::ImportIteratorMethodInheritedLocals.

            var result  = PooledStringBuilder.GetInstance();
            var builder = result.Builder;

            builder.Append('<');
            if (localName != null)
            {
                Debug.Assert(localName.IndexOf('.') == -1);
                builder.Append(localName);
            }

            builder.Append('>');

            if (kind == SynthesizedLocalKind.LambdaDisplayClass)
            {
                builder.Append((char)GeneratedNameKind.DisplayClassLocalOrField);
            }
            else if (kind == SynthesizedLocalKind.UserDefined)
            {
                builder.Append((char)GeneratedNameKind.HoistedLocalField);
            }
            else
            {
                builder.Append((char)GeneratedNameKind.HoistedSynthesizedLocalField);
            }

            builder.Append("__");
            builder.Append(slotIndex + 1);

            return(result.ToStringAndFree());
        }
Ejemplo n.º 7
0
        string IDkmClrFullNameProvider.GetClrValidIdentifier(
            DkmInspectionContext inspectionContext,
            string identifier
            )
        {
            var  pooledBuilder = PooledStringBuilder.GetInstance();
            var  builder       = pooledBuilder.Builder;
            bool sawInvalidIdentifier;

            AppendIdentifierEscapingPotentialKeywords(
                builder,
                identifier,
                out sawInvalidIdentifier
                );
            var result = sawInvalidIdentifier ? null : builder.ToString();

            pooledBuilder.Free();
            return(result);
        }
        /// <summary>
        /// Gets the concatenated value text for the token list.
        /// </summary>
        /// <returns>The concatenated value text, or an empty string if there are no tokens in the list.</returns>
        internal static string GetValueText(this SyntaxTokenList tokens)
        {
            switch (tokens.Count)
            {
            case 0:
                return(string.Empty);

            case 1:
                return(tokens[0].ValueText);

            default:
                var pooledBuilder = PooledStringBuilder.GetInstance();
                foreach (var token in tokens)
                {
                    pooledBuilder.Builder.Append(token.ValueText);
                }
                return(pooledBuilder.ToStringAndFree());
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Returns the Documentation Comment ID for the symbol, or null if the symbol doesn't
        /// support documentation comments.
        /// </summary>
        public virtual string GetDocumentationCommentId()
        {
            // NOTE: we're using a try-finally here because there's a test that specifically
            // triggers an exception here to confirm that some symbols don't have documentation
            // comment IDs.  We don't care about "leaks" in such cases, but we don't want spew
            // in the test output.
            var pool = PooledStringBuilder.GetInstance();

            try
            {
                StringBuilder builder = pool.Builder;
                DocumentationCommentIDVisitor.Instance.Visit(this, builder);
                return(builder.Length == 0 ? null : builder.ToString());
            }
            finally
            {
                pool.Free();
            }
        }
        public string GenerateLinkRels()
        {
            if (_linkParts == null)
            {
                return(string.Empty);
            }

            var sb = PooledStringBuilder.Rent();

            foreach (var part in _linkParts)
            {
                var tag = new TagBuilder("link");
                tag.MergeAttributes(part, true);

                sb.AppendLine(tag.ToString(TagRenderMode.SelfClosing));
            }

            return(sb.ToStringAndReturn());
        }
Ejemplo n.º 11
0
        private void MakeInterpolatedStringFormat(BoundInterpolatedString node, out BoundExpression format, out ArrayBuilder <BoundExpression> expressions)
        {
            _factory.Syntax = node.Syntax;
            int n             = node.Parts.Length - 1;
            var formatString  = PooledStringBuilder.GetInstance();
            var stringBuilder = formatString.Builder;

            expressions = ArrayBuilder <BoundExpression> .GetInstance(n + 1);

            int nextFormatPosition = 0;

            for (int i = 0; i <= n; i++)
            {
                var part   = node.Parts[i];
                var fillin = part as BoundStringInsert;
                if (fillin == null)
                {
                    Debug.Assert(part is BoundLiteral && part.ConstantValue != null);
                    // this is one of the literal parts
                    stringBuilder.Append(part.ConstantValue.StringValue);
                }
                else
                {
                    // this is one of the expression holes
                    stringBuilder.Append('{').Append(nextFormatPosition++);
                    if (fillin.Alignment != null && !fillin.Alignment.HasErrors)
                    {
                        stringBuilder.Append(',').Append(fillin.Alignment.ConstantValue.Int64Value);
                    }
                    if (fillin.Format != null && !fillin.Format.HasErrors)
                    {
                        stringBuilder.Append(':').Append(fillin.Format.ConstantValue.StringValue);
                    }
                    stringBuilder.Append('}');
                    var value = fillin.Value;

                    expressions.Add(value); // NOTE: must still be lowered
                }
            }

            format = _factory.StringLiteral(formatString.ToStringAndFree());
        }
Ejemplo n.º 12
0
        internal string GetName(TMethodSymbol method, bool includeParameterTypes, bool includeParameterNames, ArrayBuilder <string?>?argumentValues = null)
        {
            var pooled  = PooledStringBuilder.GetInstance();
            var builder = pooled.Builder;

            // "full name" of method...
            AppendFullName(builder, method);

            // parameter list...
            var parameters            = ((IMethodSymbol)method.GetISymbol()).Parameters;
            var includeArgumentValues = argumentValues != null && parameters.Length == argumentValues.Count;

            if (includeParameterTypes || includeParameterNames || includeArgumentValues)
            {
                builder.Append('(');
                for (int i = 0; i < parameters.Length; i++)
                {
                    if (i > 0)
                    {
                        builder.Append(", ");
                    }

                    var parameter = parameters[i];

                    if (includeParameterTypes)
                    {
                        AppendParameterTypeName(builder, parameter);
                    }

                    if (includeParameterNames)
                    {
                        if (includeParameterTypes)
                        {
                            builder.Append(' ');
                        }

                        builder.Append(parameter.Name);
                    }

                    if (includeArgumentValues)
                    {
                        var argumentValue = argumentValues ![i];
Ejemplo n.º 13
0
        /// <remarks>
        /// <see cref="Exception.StackTrace"/> produces inconvenient strings:
        /// there are line breaks and "at" is localized.
        /// </remarks>
        private static string GetStackTraceString(Exception e)
        {
            PooledStringBuilder pooled  = PooledStringBuilder.GetInstance();
            StringBuilder       builder = pooled.Builder;

            // No file info, since that would disrupt bucketing.
            foreach (StackFrame frame in new StackTrace(e, fNeedFileInfo: false).GetFrames())
            {
                MethodBase method = frame.GetMethod();
                if (method == null)
                {
                    continue;
                }

                builder.Append(method);
                builder.Append(';'); // Method signatures should not contain semicolons.
            }

            return(pooled.ToStringAndFree());
        }
Ejemplo n.º 14
0
    private void LogSystemInfo()
    {
        using (PooledStringBuilder builder = PooledStringBuilder.Create())
        {
            StringBuilder b = builder.Builder;

            b.Append("---- DEVICE SPECS (ACCORDING TO UNITY)---\n");
            b.Append("Device Name: ").Append(SystemInfo.graphicsDeviceName).Append('\n');
            b.Append("VRAM: ").Append(SystemInfo.graphicsMemorySize).Append('\n');
            b.Append("Shader Level: ").Append(SystemInfo.graphicsShaderLevel).Append('\n');
            b.Append("Processors: ").Append(SystemInfo.processorCount).Append('\n');
            b.Append("Render Targets: ").Append(SystemInfo.supportedRenderTargetCount).Append('\n');
            b.Append("3D Textures: ").Append(SystemInfo.supports3DTextures).Append('\n');
            b.Append("Instancing: ").Append(SystemInfo.supportsInstancing).Append('\n');
            b.Append("RAM: ").Append(SystemInfo.systemMemorySize).Append('\n');
            b.Append("Screen: ").Append(Screen.width).Append('x').Append(Screen.height).Append('\n');

            Logger.Log(b.ToString());
        }
    }
Ejemplo n.º 15
0
 public string ToSymbolString(char sep = ';', bool sort = true)
 {
     using (var symbols = ListPool <DefineEditData> .Get())
         using (var sb = PooledStringBuilder.Get()) {
             Get(symbols, sort);
             return(symbols.Aggregate(sb.stringBuilder, (acc, cur) =>
             {
                 if (!cur.willDefine)
                 {
                     return acc;
                 }
                 if (acc.Length > 0 && acc[acc.Length - 1] != sep)
                 {
                     acc.Append(sep);
                 }
                 acc.Append(cur.symbol);
                 return acc;
             }).ToString());
         }
 }
Ejemplo n.º 16
0
        public RSGroupInfo(RSGroupAttribute inAttribute, FieldInfo inFieldInfo)
        {
            Id      = inAttribute.Id;
            IdHash  = ScriptUtils.Hash(Id);
            GroupId = new RSGroupId(IdHash);

            Name        = inAttribute.Name ?? inFieldInfo.Name;
            Description = inAttribute.Description ?? string.Empty;
            Icon        = inAttribute.Icon ?? string.Empty;

            using (var psb = PooledStringBuilder.Alloc())
            {
                psb.Builder.Append(Name);
                if (!string.IsNullOrEmpty(Description))
                {
                    psb.Builder.Append("\n - ").Append(Description);
                }
                Tooltip = psb.Builder.ToString();
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Indicates that this method is the iterator state machine for the method named in the record.
        /// </summary>
        /// <remarks>
        /// Appears when are iterator methods.
        /// Exposed for <see cref="T:Roslyn.Test.PdbUtilities.PdbToXmlConverter"/>.
        /// </remarks>
        public static string DecodeForwardIteratorRecord(ImmutableArray <byte> bytes)
        {
            int offset = 0;

            var pooled  = PooledStringBuilder.GetInstance();
            var builder = pooled.Builder;

            while (true)
            {
                char ch = (char)ReadInt16(bytes, ref offset);
                if (ch == 0)
                {
                    break;
                }

                builder.Append(ch);
            }

            return(pooled.ToStringAndFree());
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Convert a string to lower case per Unicode
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string ToLower(string value)
        {
            if ((object)value == null)
            {
                return(null);
            }

            if (value.Length == 0)
            {
                return(value);
            }

            var           pooledStrbuilder = PooledStringBuilder.GetInstance();
            StringBuilder builder          = pooledStrbuilder.Builder;

            builder.Append(value);
            ToLower(builder);

            return(pooledStrbuilder.ToStringAndFree());
        }
Ejemplo n.º 19
0
        private string BuildTypeArgumentString(TypeSymbol typeArg)
        {
            Debug.Assert(typeArg.Kind != SymbolKind.TypeParameter); //must be a closed type

            string typeArgumentsOpt = null;
            string assemblyNameSuffix;
            string typeArgString = typeArg.IsArray() ?
                                   BuildArrayTypeString((ArrayTypeSymbol)typeArg, out assemblyNameSuffix) :
                                   BuildTypeString(typeArg, out typeArgumentsOpt, out assemblyNameSuffix);

            PooledStringBuilder pool    = PooledStringBuilder.GetInstance();
            StringBuilder       builder = pool.Builder;

            builder.Append("[");
            builder.Append(typeArgString);
            AppendTypeArguments(builder, typeArgumentsOpt);
            builder.Append(assemblyNameSuffix);
            builder.Append("]");
            return(pool.ToStringAndFree());
        }
Ejemplo n.º 20
0
        public static string GetMemberName(
            string name,
            TypeSymbol explicitInterfaceTypeOpt,
            string aliasQualifierOpt
            )
        {
            if ((object)explicitInterfaceTypeOpt == null)
            {
                return(name);
            }

            // TODO: Revisit how explicit interface implementations are named.
            // CONSIDER (vladres): we should never generate identical names for different methods.

            string interfaceName = explicitInterfaceTypeOpt.ToDisplayString(
                SymbolDisplayFormat.ExplicitInterfaceImplementationFormat
                );

            PooledStringBuilder pooled  = PooledStringBuilder.GetInstance();
            StringBuilder       builder = pooled.Builder;

            if (!string.IsNullOrEmpty(aliasQualifierOpt))
            {
                builder.Append(aliasQualifierOpt);
                builder.Append("::");
            }

            foreach (char ch in interfaceName)
            {
                // trim spaces to match metadata name (more closely - could still be truncated)
                if (ch != ' ')
                {
                    builder.Append(ch);
                }
            }

            builder.Append(".");
            builder.Append(name);

            return(pooled.ToStringAndFree());
        }
Ejemplo n.º 21
0
        public String GetOffsetCoordinatesArt(HexCoordinateSystem grid)
        {
            Vector2             pt = grid.GetOffsetCoordinates(this);
            int                 x1 = (int)pt.x;
            int                 y1 = (int)pt.y;
            PooledStringBuilder sb =
                StringBuilderPool.Instance.GetStringBuilder();

            // sb.Append(" _ _ ");
            sb.Append("/     \\");
            sb.Append('\n');
            sb.Append("/");
            int len = x1.ToString().Length;

            len++;
            len += y1.ToString().Length;
            int off = "       ".Length - len;
            int lef = off / 2;

            for (int i = lef; i > 0; i--)
            {
                sb.Append(' ');
            }
            sb.Append(x1);
            sb.Append(",");
            sb.Append(y1);
            for (int i = off - lef; i > 0; i--)
            {
                sb.Append(' ');
            }
            sb.Append("\\");
            sb.Append('\n');
            sb.Append("\\       /");
            sb.Append('\n');
            sb.Append("\\ _ _ /");
            String s = sb.ToString();

            sb.ReturnToPool();
            sb = null;
            return(s);
        }
Ejemplo n.º 22
0
        internal override void Dump(DynamicAnalysisDataReader reader, string[] sourceLines)
        {
            var output = PooledStringBuilder.GetInstance();

            output.Builder.AppendLine("Template code for checking instrumentation results:");

            for (int method = 1; method <= reader.Methods.Length; method++)
            {
                var snippets = GetActualSnippets(method, reader, sourceLines);
                if (snippets.Length == 0)
                {
                    continue;
                }

                string methodTermination = GetTermination(0, snippets.Length);
                if (snippets[0] == null)
                {
                    output.Builder.AppendLine($"checker.Method({method}, 1){methodTermination}");
                }
                else
                {
                    output.Builder.AppendLine(
                        $"checker.Method({method}, 1, \"{snippets[0]}\"){methodTermination}"
                        );
                }

                for (int index = 1; index < snippets.Length; index++)
                {
                    string termination = GetTermination(index, snippets.Length);
                    if (snippets[index] == null)
                    {
                        output.Builder.AppendLine($"    .True(){termination}");
                    }
                    else
                    {
                        output.Builder.AppendLine($"    .True(\"{snippets[index]}\"){termination}");
                    }
                }
            }
            AssertEx.Fail(output.ToStringAndFree());
        }
Ejemplo n.º 23
0
        public override string ToString()
        {
            PooledStringBuilder sb = StringBuilderPool.Instance.GetStringBuilder();

            try
            {
                QuestBranch branch = root;
                sb.Append(branch.Localized);
                sb.Append('\n');
                while (branch.Branches.Length > 0)
                {
                    int i = branch.Branches.Length - 1;
                    for (; i >= 0; i--)
                    {
                        // go through all branches
                        if (branch.Branches[i].Taken)
                        {
                            // follow branch that was taken
                            branch = branch.Branches[i];
                            sb.Append('\n');
                            sb.Append(branch.Localized);
                            sb.Append('\n');
                            break;
                        }
                    }
                    if (i == -1)
                    {
                        // made it through all branches
                        break;
                    }
                }
            }
            catch (PooledException e)
            {
                // e.printStackTrace();
            }
            string s = sb.ToString();

            sb.ReturnToPool();
            return(s);
        }
Ejemplo n.º 24
0
        internal PooledStringBuilder appendModuleAncestry(PooledStringBuilder sb, PartModule module, uint tabs = 1)
        {
            sb.Append('\n');
            for (ushort i = 0; i < tabs; i++)
            {
                sb.Append('\t');
            }
            sb.Append("Module: ");

            if (module != null)
            {
                sb.Append(module.moduleName);
                this.appendPartAncestry(sb, module.part, tabs + 1u);
            }
            else
            {
                sb.Append("null");
            }

            return(sb);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Constructs the string identifier for a dependency from its target framework, provider type and dependency model ID.
        /// </summary>
        /// <remarks>
        /// This string has form <c>"tfm-name\provider-type\model-id"</c>.
        /// <list type="bullet">
        ///   <item>All characters are lower-case.</item>
        ///   <item><c>".."</c> is replaced with <c>"__"</c>.</item>
        ///   <item><c>"/"</c> is replaced with <c>"\"</c>.</item>
        ///   <item>Any trailing <c>"\"</c> characters are trimmed.</item>
        /// </list>
        /// </remarks>
        /// <param name="targetFramework"></param>
        /// <param name="providerType"></param>
        /// <param name="modelId"></param>
        public static string GetID(ITargetFramework targetFramework, string providerType, string modelId)
        {
            Requires.NotNull(targetFramework, nameof(targetFramework));
            Requires.NotNullOrEmpty(providerType, nameof(providerType));
            Requires.NotNullOrEmpty(modelId, nameof(modelId));

            var sb = PooledStringBuilder.GetInstance();

            sb.Append(targetFramework.ShortName);
            sb.Append('\\');
            sb.Append(providerType);
            sb.Append('\\');
            int offset = sb.Length;

            sb.Append(modelId);
            // normalize modelId (without allocating)
            sb.Replace('/', '\\', offset, modelId.Length);
            sb.Replace("..", "__", offset, modelId.Length);
            sb.TrimEnd(Delimiter.BackSlash);
            return(sb.ToStringAndFree());
        }
Ejemplo n.º 26
0
        internal PooledStringBuilder appendPartAncestry(PooledStringBuilder sb, Part part, uint tabs = 1)
        {
            sb.Append('\n');
            for (ushort i = 0; i < tabs; i++)
            {
                sb.Append('\t');
            }
            sb.Append("Part: ");

            if (part != null)
            {
                sb.AppendFormat("'{0}' ({1})", part.partInfo.title, part.partName);
                this.appendVessel(sb, part.vessel, tabs + 1u);
            }
            else
            {
                sb.Append("null");
            }

            return(sb);
        }
Ejemplo n.º 27
0
        public virtual string ValueUnitString()
        {
            if (this.Value == null || this.Units == null)
            {
                using (PooledStringBuilder sb = PooledStringBuilder.Get())
                {
                    if (this.Value == null)
                    {
                        sb.AppendFormat("{0}: Value is null during ValueUnitString\n", this.Label);
                    }
                    if (this.Units == null)
                    {
                        sb.AppendFormat("{0}: Units is null during ValueUnitString\n", this.Label);
                    }

                    ToadicusTools.Logging.PostErrorMessage(sb.ToString());
                }
            }

            return(string.Format("{0}{1}", this.Value == null ? "NULL" : this.Value.ToString(), this.Units));
        }
Ejemplo n.º 28
0
        public string GetPreviewString(RSTriggerInfo inTriggerContext, RSLibrary inLibrary)
        {
            using (PooledStringBuilder psb = PooledStringBuilder.Alloc())
            {
                var sb = psb.Builder;

                if (!Enabled)
                {
                    sb.Append("[Disabled] ");
                }

                if (!string.IsNullOrEmpty(Name))
                {
                    sb.Append(Name).Append(" :: ");
                }

                sb.Append(TriggerId.ToString(inLibrary));

                return(sb.ToString());
            }
        }
Ejemplo n.º 29
0
        public static CompletionItem CreateAttributeItemWithoutSuffix(CompletionItem attributeItem, string attributeNameWithoutSuffix)
        {
            Debug.Assert(!attributeItem.Properties.ContainsKey(AttributeFullName));

            // Remember the full type name so we can get the symbol when description is displayed.
            var newProperties = attributeItem.Properties.Add(AttributeFullName, attributeItem.DisplayText);

            var sortTextBuilder = PooledStringBuilder.GetInstance();

            sortTextBuilder.Builder.AppendFormat(SortTextFormat, attributeNameWithoutSuffix, attributeItem.InlineDescription);

            return(CompletionItem.Create(
                       displayText: attributeNameWithoutSuffix,
                       sortText: sortTextBuilder.ToStringAndFree(),
                       properties: newProperties,
                       tags: attributeItem.Tags,
                       rules: attributeItem.Rules,
                       displayTextPrefix: attributeItem.DisplayTextPrefix,
                       displayTextSuffix: attributeItem.DisplayTextSuffix,
                       inlineDescription: attributeItem.InlineDescription));
        }
Ejemplo n.º 30
0
        public virtual string FormatTypeArguments(
            Type[] typeArguments,
            CommonTypeNameFormatterOptions options
            )
        {
            if (typeArguments == null)
            {
                throw new ArgumentNullException(nameof(typeArguments));
            }

            if (typeArguments.Length == 0)
            {
                throw new ArgumentException(null, nameof(typeArguments));
            }

            var pooled  = PooledStringBuilder.GetInstance();
            var builder = pooled.Builder;

            builder.Append(GenericParameterOpening);

            var first = true;

            foreach (var typeArgument in typeArguments)
            {
                if (first)
                {
                    first = false;
                }
                else
                {
                    builder.Append(", ");
                }

                builder.Append(FormatTypeName(typeArgument, options));
            }

            builder.Append(GenericParameterClosing);

            return(pooled.ToStringAndFree());
        }