diff --git a/Cpp2IL.Core/Utils/AsmResolver/AsmResolverAssemblyPopulator.cs b/Cpp2IL.Core/Utils/AsmResolver/AsmResolverAssemblyPopulator.cs index 37843b43..5accac44 100644 --- a/Cpp2IL.Core/Utils/AsmResolver/AsmResolverAssemblyPopulator.cs +++ b/Cpp2IL.Core/Utils/AsmResolver/AsmResolverAssemblyPopulator.cs @@ -278,7 +278,13 @@ public static void PopulateCustomAttributes(AssemblyAnalysisContext asmContext) CopyCustomAttributes(field, field.GetExtraData("AsmResolverField")!.CustomAttributes); foreach (var property in type.Properties) - CopyCustomAttributes(property, property.GetExtraData("AsmResolverProperty")!.CustomAttributes); + { + // Property with no accessors are skipped in CopyPropertiesInType. + // Skip copying custom attributes, too. + var propertyDef = property.GetExtraData("AsmResolverProperty"); + if (propertyDef == null) continue; + CopyCustomAttributes(property, propertyDef.CustomAttributes); + } foreach (var eventDefinition in type.Events) CopyCustomAttributes(eventDefinition, eventDefinition.GetExtraData("AsmResolverEvent")!.CustomAttributes); @@ -443,6 +449,10 @@ private static void CopyPropertiesInType(ReferenceImporter importer, TypeAnalysi { foreach (var propertyCtx in typeContext.Properties) { + // Skip properties whose getter and setter were both stripped. + if (propertyCtx.Getter == null && propertyCtx.Setter == null) + continue; + var propertyTypeSig = propertyCtx.ToTypeSignature(importer.TargetModule); var propertySignature = propertyCtx.IsStatic ? PropertySignature.CreateStatic(propertyTypeSig) diff --git a/LibCpp2IL/Metadata/Il2CppPropertyDefinition.cs b/LibCpp2IL/Metadata/Il2CppPropertyDefinition.cs index 2d1b598d..3743ff0b 100644 --- a/LibCpp2IL/Metadata/Il2CppPropertyDefinition.cs +++ b/LibCpp2IL/Metadata/Il2CppPropertyDefinition.cs @@ -39,11 +39,29 @@ public Il2CppTypeDefinition? DeclaringType public Il2CppMethodDefinition? Setter => LibCpp2IlMain.TheMetadata == null || set.IsNull || DeclaringType == null ? null : LibCpp2IlMain.TheMetadata.GetMethodDefinitionFromIndex(DeclaringType.FirstMethodIdx + set); - public Il2CppTypeReflectionData? PropertyType => LibCpp2IlMain.TheMetadata == null ? null : Getter == null ? Setter!.Parameters![0].Type : Getter!.ReturnType; + public Il2CppTypeReflectionData? PropertyType + { + get + { + if (LibCpp2IlMain.TheMetadata == null) return null; + if (Getter != null) return Getter.ReturnType; + if (Setter != null && Setter.Parameters is { Length: > 0 }) return Setter.Parameters[^1].Type; + return null; + } + } - public Il2CppType? RawPropertyType => LibCpp2IlMain.TheMetadata == null ? null : Getter == null ? Setter!.Parameters![0].RawType : Getter!.RawReturnType; + public Il2CppType? RawPropertyType + { + get + { + if (LibCpp2IlMain.TheMetadata == null) return null; + if (Getter != null) return Getter.RawReturnType; + if (Setter != null && Setter.Parameters is { Length: > 0 }) return Setter.Parameters[^1].RawType; + return null; + } + } - public bool IsStatic => Getter == null ? Setter!.IsStatic : Getter!.IsStatic; + public bool IsStatic => Getter?.IsStatic ?? Setter?.IsStatic ?? false; public uint Token => token; public override void Read(ClassReadingBinaryReader reader)