mirror of
https://git.naxdy.org/Mirror/Ryujinx.git
synced 2025-03-29 10:40:18 +00:00
* dotnet format style --severity info Some changes were manually reverted. * dotnet format analyzers --serverity info Some changes have been minimally adapted. * Restore a few unused methods and variables * Silence dotnet format IDE0060 warnings * Silence dotnet format IDE0059 warnings * Address or silence dotnet format IDE1006 warnings * Address dotnet format CA1816 warnings * Address or silence dotnet format CA2211 warnings * Silence CA1806 and CA1834 issues * Fix formatting for switch expressions * Address most dotnet format whitespace warnings * Apply dotnet format whitespace formatting A few of them have been manually reverted and the corresponding warning was silenced * Revert formatting changes for while and for-loops * Format if-blocks correctly * Run dotnet format whitespace after rebase * Run dotnet format style after rebase * Run dotnet format analyzers after rebase * Run dotnet format after rebase and remove unused usings - analyzers - style - whitespace * Add comments to disabled warnings * Remove a few unused parameters * Replace MmeShadowScratch with Array256<uint> * Simplify properties and array initialization, Use const when possible, Remove trailing commas * Run dotnet format after rebase * Address IDE0251 warnings * Revert "Simplify properties and array initialization, Use const when possible, Remove trailing commas" This reverts commit 9462e4136c0a2100dc28b20cf9542e06790aa67e. * dotnet format whitespace after rebase * First dotnet format pass * Second dotnet format pass * Fix build issues * Fix StructArrayHelpers.cs * Apply suggestions from code review Co-authored-by: Ac_K <Acoustik666@gmail.com> * Fix return statements * Fix naming rule violations * Update src/Ryujinx.Common/Utilities/StreamUtils.cs Co-authored-by: Ac_K <Acoustik666@gmail.com> * Add trailing commas * Address review feedback * Address review feedback * Rename remaining type parameters to TKey and TValue * Fix manual formatting for logging levels * Fix spacing before comments --------- Co-authored-by: Ac_K <Acoustik666@gmail.com>
84 lines
2.1 KiB
C#
84 lines
2.1 KiB
C#
#nullable enable
|
|
using System;
|
|
using System.Reflection;
|
|
using System.Text;
|
|
|
|
namespace Ryujinx.Common.Logging.Formatters
|
|
{
|
|
internal static class DynamicObjectFormatter
|
|
{
|
|
private static readonly ObjectPool<StringBuilder> _stringBuilderPool = SharedPools.Default<StringBuilder>();
|
|
|
|
public static string? Format(object? dynamicObject)
|
|
{
|
|
if (dynamicObject is null)
|
|
{
|
|
return null;
|
|
}
|
|
|
|
StringBuilder sb = _stringBuilderPool.Allocate();
|
|
|
|
try
|
|
{
|
|
Format(sb, dynamicObject);
|
|
|
|
return sb.ToString();
|
|
}
|
|
finally
|
|
{
|
|
_stringBuilderPool.Release(sb);
|
|
}
|
|
}
|
|
|
|
public static void Format(StringBuilder sb, object? dynamicObject)
|
|
{
|
|
if (dynamicObject is null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
PropertyInfo[] props = dynamicObject.GetType().GetProperties();
|
|
|
|
sb.Append('{');
|
|
|
|
foreach (var prop in props)
|
|
{
|
|
sb.Append(prop.Name);
|
|
sb.Append(": ");
|
|
|
|
if (typeof(Array).IsAssignableFrom(prop.PropertyType))
|
|
{
|
|
Array? array = (Array?)prop.GetValue(dynamicObject);
|
|
|
|
if (array is not null)
|
|
{
|
|
foreach (var item in array)
|
|
{
|
|
sb.Append(item);
|
|
sb.Append(", ");
|
|
}
|
|
|
|
if (array.Length > 0)
|
|
{
|
|
sb.Remove(sb.Length - 2, 2);
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sb.Append(prop.GetValue(dynamicObject));
|
|
}
|
|
|
|
sb.Append(" ; ");
|
|
}
|
|
|
|
// We remove the final ';' from the string
|
|
if (props.Length > 0)
|
|
{
|
|
sb.Remove(sb.Length - 3, 3);
|
|
}
|
|
|
|
sb.Append('}');
|
|
}
|
|
}
|
|
}
|