Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Cpp2IL.Core/Utils/AsmResolver/AsmResolverAssemblyPopulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,13 @@ public static void PopulateCustomAttributes(AssemblyAnalysisContext asmContext)
CopyCustomAttributes(field, field.GetExtraData<FieldDefinition>("AsmResolverField")!.CustomAttributes);

foreach (var property in type.Properties)
CopyCustomAttributes(property, property.GetExtraData<PropertyDefinition>("AsmResolverProperty")!.CustomAttributes);
{
// Property with no accessors are skipped in CopyPropertiesInType.
// Skip copying custom attributes, too.
var propertyDef = property.GetExtraData<PropertyDefinition>("AsmResolverProperty");
if (propertyDef == null) continue;
CopyCustomAttributes(property, propertyDef.CustomAttributes);
}

foreach (var eventDefinition in type.Events)
CopyCustomAttributes(eventDefinition, eventDefinition.GetExtraData<EventDefinition>("AsmResolverEvent")!.CustomAttributes);
Expand Down Expand Up @@ -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)
Expand Down
24 changes: 21 additions & 3 deletions LibCpp2IL/Metadata/Il2CppPropertyDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down