CS: Add unsafe modifier to struct constructors where necessary (CS0214)

This commit is contained in:
Katy Coe
2020-06-20 21:11:03 +02:00
parent d479431585
commit e0fe7fa1b9

View File

@@ -16,6 +16,12 @@ namespace Il2CppInspector.Reflection
public static readonly string TypeConstructorName = ".cctor";
// Struct construvctors must initialize all non-literal fields in the struct
// If any of them are of an unsafe type, the constructor must also be declared unsafe
public override bool RequiresUnsafeContext => base.RequiresUnsafeContext ||
(!IsAbstract && DeclaringType.IsValueType &&
DeclaringType.DeclaredFields.Any(f => !f.IsLiteral && f.IsStatic == IsStatic && f.RequiresUnsafeContext));
public override MemberTypes MemberType => MemberTypes.Constructor;
public ConstructorInfo(Il2CppInspector pkg, int methodIndex, TypeInfo declaringType) : base(pkg, methodIndex, declaringType) { }