Beispiel #1
0
        private static void PrintResult(IndentingStringBuilder sb, string moduleName, ResultInfo result)
        {
            string descriptionArgs;

            if (result.IsRange)
            {
                descriptionArgs = $"{result.DescriptionStart}, {result.DescriptionEnd}";
            }
            else
            {
                descriptionArgs = $"{result.DescriptionStart}";
            }

            sb.AppendLine(GetXmlDoc(result));

            string resultCtor = $"new Result.Base(Module{moduleName}, {descriptionArgs});";

            sb.Append($"public static Result.Base {result.Name} ");

            if (EstimateCilSize(result) > InlineThreshold)
            {
                sb.AppendLine($"{{ [MethodImpl(MethodImplOptions.AggressiveInlining)] get => {resultCtor} }}");
            }
            else
            {
                sb.AppendLine($"=> {resultCtor}");
            }
        }
Beispiel #2
0
        private static string PrintArchive(ReadOnlySpan <byte> data)
        {
            var sb = new IndentingStringBuilder();

            sb.AppendLine(GetHeader());
            sb.AppendLine();

            sb.AppendLine("using System;");
            sb.AppendLine();

            sb.AppendLine("namespace LibHac");
            sb.AppendLineAndIncrease("{");

            sb.AppendLine("internal partial class ResultNameResolver");
            sb.AppendLineAndIncrease("{");

            sb.AppendLine("private static ReadOnlySpan<byte> ArchiveData => new byte[]");
            sb.AppendLineAndIncrease("{");

            for (int i = 0; i < data.Length; i++)
            {
                if (i % 16 != 0)
                {
                    sb.Append(" ");
                }
                sb.Append($"0x{data[i]:x2}");

                if (i != data.Length - 1)
                {
                    sb.Append(",");
                    if (i % 16 == 15)
                    {
                        sb.AppendLine();
                    }
                }
            }

            sb.AppendLine();
            sb.DecreaseAndAppendLine("};");
            sb.DecreaseAndAppendLine("}");
            sb.DecreaseAndAppendLine("}");

            return(sb.ToString());
        }