Refactor some string output helper functions into extension methods
This commit is contained in:
@@ -55,21 +55,4 @@ namespace Il2CppInspector.Reflection
|
||||
public static IList<CustomAttributeData> GetCustomAttributes(PropertyInfo prop) => getCustomAttributes(prop.Assembly, prop.Definition.token, prop.Definition.customAttributeIndex);
|
||||
public static IList<CustomAttributeData> GetCustomAttributes(TypeInfo type) => getCustomAttributes(type.Assembly, type.Definition.token, type.Definition.customAttributeIndex);
|
||||
}
|
||||
|
||||
public static class IEnumerableCustomAttributeDataExtensions
|
||||
{
|
||||
public static string ToString(this IEnumerable<CustomAttributeData> attributes, string linePrefix = "", string attributePrefix = "", bool inline = false) {
|
||||
var sb = new StringBuilder();
|
||||
|
||||
foreach (var cad in attributes) {
|
||||
var name = cad.AttributeType.CSharpName;
|
||||
var suffix = name.LastIndexOf("Attribute", StringComparison.Ordinal);
|
||||
if (suffix != -1)
|
||||
name = name[..suffix];
|
||||
sb.Append($"{linePrefix}[{attributePrefix}{name}] {(inline? "/*" : "//")} {Il2CppModel.FormatAddress((ulong)cad.VirtualAddress)}{(inline? " */ " : "\n")}");
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user