CS: Fix enumeration scoping on default field values (CS0103)

This commit is contained in:
Katy Coe
2020-06-22 18:38:16 +02:00
parent 2791721dd1
commit ef22c6628b
2 changed files with 2 additions and 2 deletions

View File

@@ -390,7 +390,7 @@ namespace Il2CppInspector.Outputs
else else
sb.Append($"{field.FieldType.GetScopedCSharpName(scope)} {field.CSharpSafeName}"); sb.Append($"{field.FieldType.GetScopedCSharpName(scope)} {field.CSharpSafeName}");
if (field.HasDefaultValue) if (field.HasDefaultValue)
sb.Append($" = {field.DefaultValueString}"); sb.Append($" = {field.GetDefaultValueString(scope)}");
sb.Append(";"); sb.Append(";");
// Don't output field indices for const fields (they don't have any storage) // Don't output field indices for const fields (they don't have any storage)
// or open generic types (they aren't known until runtime) // or open generic types (they aren't known until runtime)

View File

@@ -34,7 +34,7 @@ namespace Il2CppInspector.Reflection {
public bool HasDefaultValue => (Attributes & FieldAttributes.HasDefault) != 0; public bool HasDefaultValue => (Attributes & FieldAttributes.HasDefault) != 0;
public object DefaultValue { get; } public object DefaultValue { get; }
public string DefaultValueString => HasDefaultValue ? DefaultValue.ToCSharpValue(FieldType) : ""; public string GetDefaultValueString(Scope usingScope = null) => HasDefaultValue ? DefaultValue.ToCSharpValue(FieldType, usingScope) : "";
// Information/flags about the field // Information/flags about the field
public FieldAttributes Attributes { get; } public FieldAttributes Attributes { get; }