dotnet / extensions

This repository contains a suite of libraries that provide facilities commonly needed when creating production-ready applications.
MIT License
2.55k stars 730 forks source link

[LogProperties(Transitive = true)] generates uncompilable code if property is of List<T> type #5207

Closed wasker closed 3 weeks ago

wasker commented 3 weeks ago

Description

[LogProperties(Transitive = true)] will result in generating uncompilable code, if object's property is of List<T> type.

Reproduction Steps

using System.Collections.Generic;
using Microsoft.Extensions.Logging;

namespace LoggerMessageCodeGen;
#pragma warning disable EXTEXP0003 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.

internal partial class Program
{
    static void Main(string[] args)
    {
    }

    internal partial class Log
    {
        [LoggerMessage(EventId = 1, EventName = "Test", Level = LogLevel.Information)]
        public static partial void Test(ILogger logger, [LogProperties(Transitive = true)] Test obj);
    }
}

public sealed class Test
{
    // This property will generate bad code when LogProperties.Transitive = true.
    public List<string> Blah { get; set; }
}

Expected behavior

Generated code should be compilable.

Actual behavior

Generated code doesn't compile.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

tarekgh commented 3 weeks ago

CC @geeknoid @xakep139

xakep139 commented 3 weeks ago

@wasker thank you for reporting this!