Repository: dotnet/runtime
File: src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/SignatureHelper.cs (C#)

Code before:
        private static void WriteCustomModifiers(CustomModifiersEncoder encoder, Type[] customModifiers, bool isOptional, ModuleBuilderImpl module)
        {
            // GetOptionalCustomModifiers and GetRequiredCustomModifiers return modifiers in reverse order
            for (int i = customModifiers.Length - 1; i >= 0; i--)
            {
                Type modifier = customModifiers[i];
                encoder.AddModifier(module.GetTypeHandle(modifier), isOptional);
            }
        }

        private static void WriteParametersSignature(ModuleBuilderImpl module, Type[]? parameters,
            ParametersEncoder parameterEncoder, Type[][]? requiredModifiers = null, Type[][]? optionalModifiers = null)
        {
            if (parameters != null) // If parameters null, just keep the ParametersEncoder empty
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    ParameterTypeEncoder encoder = parameterEncoder.AddParameter();

                    Type[] modreqs = requiredModifiers != null && requiredModifiers.Length > i && requiredModifiers[i] is { } mr
                        ? mr
                        : parameters[i].GetRequiredCustomModifiers();

                    Type[] modopts = optionalModifiers != null && optionalModifiers.Length > i && optionalModifiers[i] is { } mo
                        ? mo
                        : parameters[i].GetOptionalCustomModifiers();

                    WriteSignatureForType(encoder.Type(), parameters[i], module, modreqs, modopts);
                }
            }
        }

        internal static BlobBuilder GetPropertySignature(PropertyBuilderImpl property, ModuleBuilderImpl module)
        {
            BlobBuilder propertySignature = new();

            new BlobEncoder(propertySignature).
                PropertySignature(isInstanceProperty: property.CallingConventions.HasFlag(CallingConventions.HasThis)).
                Parameters(property.ParameterTypes == null ? 0 : property.ParameterTypes.Length, out ReturnTypeEncoder retType, out ParametersEncoder paramEncoder);

            WriteSignatureForType(retType.Type(), property.PropertyType, module, property._returnTypeRequiredCustomModifiers, property._returnTypeOptionalCustomModifiers);
            WriteParametersSignature(module, property.ParameterTypes, paramEncoder, property._parameterTypeRequiredCustomModifiers, property._parameterTypeOptionalCustomModifiers);

            return propertySignature;
        }

        private static void WriteSignatureForType(SignatureTypeEncoder signature, Type type, ModuleBuilderImpl module, Type[]? requiredModifiers = null, Type[]? optionalModifiers = null)
        {
            WriteCustomModifiers(signature.CustomModifiers(), requiredModifiers ?? type.GetRequiredCustomModifiers(), isOptional: false, module);
            WriteCustomModifiers(signature.CustomModifiers(), optionalModifiers ?? type.GetOptionalCustomModifiers(), isOptional: true, module);
            if (type.IsArray)

Review comment (suggestion):
```suggestion
                    Type[]? modopts = (optionalModifiers != null && optionalModifiers.Length > i) ? optionalModifiers[i] : null;
```

Code after:
        private static void WriteCustomModifiers(CustomModifiersEncoder encoder, Type[] customModifiers, bool isOptional, ModuleBuilderImpl module)
        {
            // GetOptionalCustomModifiers and GetRequiredCustomModifiers return modifiers in reverse order
            for (int i = customModifiers.Length - 1; i >= 0; i--)
            {
                Type modifier = customModifiers[i];
                encoder.AddModifier(module.GetTypeHandle(modifier), isOptional);
            }
        }

        private static void WriteParametersSignature(ModuleBuilderImpl module, Type[]? parameters,
            ParametersEncoder parameterEncoder, Type[][]? requiredModifiers = null, Type[][]? optionalModifiers = null)
        {
            if (parameters != null) // If parameters null, just keep the ParametersEncoder empty
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    ParameterTypeEncoder encoder = parameterEncoder.AddParameter();

                    Type[]? modreqs = (requiredModifiers != null && requiredModifiers.Length > i) ? requiredModifiers[i] : null;
                    Type[]? modopts = (optionalModifiers != null && optionalModifiers.Length > i) ? optionalModifiers[i] : null;

                    WriteSignatureForType(encoder.Type(), parameters[i], module, modreqs, modopts);
                }
            }
        }

        internal static BlobBuilder GetPropertySignature(PropertyBuilderImpl property, ModuleBuilderImpl module)
        {
            BlobBuilder propertySignature = new();

            new BlobEncoder(propertySignature).
                PropertySignature(isInstanceProperty: property.CallingConventions.HasFlag(CallingConventions.HasThis)).
                Parameters(property.ParameterTypes == null ? 0 : property.ParameterTypes.Length, out ReturnTypeEncoder retType, out ParametersEncoder paramEncoder);

            WriteSignatureForType(retType.Type(), property.PropertyType, module, property._returnTypeRequiredCustomModifiers, property._returnTypeOptionalCustomModifiers);
            WriteParametersSignature(module, property.ParameterTypes, paramEncoder, property._parameterTypeRequiredCustomModifiers, property._parameterTypeOptionalCustomModifiers);

            return propertySignature;
        }

        private static void WriteSignatureForType(SignatureTypeEncoder signature, Type type, ModuleBuilderImpl module, Type[]? requiredModifiers = null, Type[]? optionalModifiers = null)
        {
            WriteCustomModifiers(signature.CustomModifiers(), requiredModifiers ?? type.GetRequiredCustomModifiers(), isOptional: false, module);
            WriteCustomModifiers(signature.CustomModifiers(), optionalModifiers ?? type.GetOptionalCustomModifiers(), isOptional: true, module);
            if (type.IsArray)
            {
                Type elementType = type.GetElementType()!;
                int rank = type.GetArrayRank();
                if (rank == 1)
                {