System.Diagnostics.CodeAnalysis Attributes not pulled into interface
For example:
[GenerateAutomaticInterface]
public class Foo : IFoo
{
public bool TryGetValue(string blah, [NotNullWhen(true)] out string? value)
{
value = null;
return true;
}
}
//--------------------------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
//
// Changes to this file may cause incorrect behavior and will be lost if the code is regenerated.
// </auto-generated>
//--------------------------------------------------------------------------------------------------
#nullable enable
namespace Test
{
[global::System.CodeDom.Compiler.GeneratedCode("AutomaticInterface", "")]
public partial interface IFoo
{
/// <inheritdoc cref="Test.Foo.TryGetValue(string, out string?)" />
bool TryGetValue(string blah, out string? value); <--- missing NotNullWhen attribute
}
}
#nullable restore
I am not sure I understand you? What's the problem?
The generated interface is missing the [NotNullWhen(true)] attribute for the out parameter when the class method specifies it. The generator should pull this attribute into the generated interface.
Perhaps a way to do this is to check if the parameters in the method have attributes and include them in the generated interface.
I am unsure if all method-attributes from a class can also be applied to an interface method. I will look into this
I think we can start with just the attributes in the System.Diagnostics.CodeAnalysis namespace.