From 320415685e997d6a0429016fbf448e04e537962a Mon Sep 17 00:00:00 2001 From: wwwDayDream Date: Mon, 20 May 2024 16:31:23 -0500 Subject: [PATCH] Implement a defaulted to false option for public fields when it works --- CessilCellsCeaChells/CeaChore/Attributes.cs | 2 +- CessilCellsCeaChells/Merges/FieldMerge.cs | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CessilCellsCeaChells/CeaChore/Attributes.cs b/CessilCellsCeaChells/CeaChore/Attributes.cs index a5e5818..747f8af 100644 --- a/CessilCellsCeaChells/CeaChore/Attributes.cs +++ b/CessilCellsCeaChells/CeaChore/Attributes.cs @@ -5,7 +5,7 @@ namespace CessilCellsCeaChells.CeaChore; public class RequiresFieldAttribute : RequiresAttribute { - [UsedImplicitly] public RequiresFieldAttribute(Type targetType, string fieldName, Type fieldType) {} + [UsedImplicitly] public RequiresFieldAttribute(Type targetType, string fieldName, Type fieldType, bool isPublic = false) {} } public class RequiresPropertyAttribute : RequiresAttribute { diff --git a/CessilCellsCeaChells/Merges/FieldMerge.cs b/CessilCellsCeaChells/Merges/FieldMerge.cs index 8f89bd3..0a93a87 100644 --- a/CessilCellsCeaChells/Merges/FieldMerge.cs +++ b/CessilCellsCeaChells/Merges/FieldMerge.cs @@ -9,6 +9,7 @@ namespace CessilCellsCeaChells.Merges; internal class FieldMerge(CustomAttribute attribute) : CessilMerge((TypeReference)attribute.ConstructorArguments[0].Value) { private readonly string FieldName = (string)attribute.ConstructorArguments[1].Value; private readonly TypeReference FieldType = (TypeReference)attribute.ConstructorArguments[2].Value; + private readonly bool IsPublic = attribute.ConstructorArguments.Count > 3 && (bool)attribute.ConstructorArguments[3].Value; internal override CustomAttribute ConvertToAttribute(AssemblyDefinition into) { @@ -19,7 +20,8 @@ internal override CustomAttribute ConvertToAttribute(AssemblyDefinition into) ConstructorArguments = { new CustomAttributeArgument(typeTypeRef, targetTypeRef), new CustomAttributeArgument(into.MainModule.TypeSystem.String, FieldName), - new CustomAttributeArgument(typeTypeRef, fieldTypeTypeRef) + new CustomAttributeArgument(typeTypeRef, fieldTypeTypeRef), + new CustomAttributeArgument(into.MainModule.TypeSystem.Boolean, IsPublic) } }; } @@ -27,7 +29,8 @@ internal override CustomAttribute ConvertToAttribute(AssemblyDefinition into) internal override bool TryMergeInto(TypeDefinition typeDefinition, out IMemberDefinition? memberDefinition) { memberDefinition = default; - var didCreate = CessilHelper.TryCreateField(typeDefinition, FieldName, GetOrImportTypeReference(typeDefinition.Module, FieldType), out var fieldDefinition); + var didCreate = CessilHelper.TryCreateField(typeDefinition, FieldName, GetOrImportTypeReference(typeDefinition.Module, FieldType), + out var fieldDefinition, IsPublic ? FieldAttributes.Public : FieldAttributes.Private); if (didCreate) memberDefinition = fieldDefinition; return didCreate;