Refactor C# keyword modifer code slightly

This commit is contained in:
Katy Coe
2019-11-10 17:46:19 +01:00
parent b980798ab5
commit 54d03b9f0f
4 changed files with 85 additions and 68 deletions

View File

@@ -5,7 +5,9 @@
*/
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
namespace Il2CppInspector.Reflection {
public class FieldInfo : MemberInfo
@@ -112,5 +114,32 @@ namespace Il2CppInspector.Reflection {
if (pkg.FieldDefaultValue.TryGetValue(fieldIndex, out object variant))
DefaultValue = variant;
}
public string GetAccessModifierString() => this switch {
{ IsPrivate: true } => "private ",
{ IsPublic: true } => "public ",
{ IsFamily: true } => "protected ",
{ IsAssembly: true } => "internal ",
{ IsFamilyOrAssembly: true } => "protected internal ",
{ IsFamilyAndAssembly: true } => "private protected ",
_ => ""
};
public string GetModifierString() {
var modifiers = new StringBuilder(GetAccessModifierString());
if (IsLiteral)
modifiers.Append("const ");
// All const fields are also static by implication
else if (IsStatic)
modifiers.Append("static ");
if (IsInitOnly)
modifiers.Append("readonly ");
if (IsPinvokeImpl)
modifiers.Append("extern ");
if (GetCustomAttributes("System.Runtime.CompilerServices.FixedBufferAttribute").Any())
modifiers.Append("fixed ");
return modifiers.ToString();
}
}
}