Solution Wide Analysis and Source Generators

I use Source Generators to implement Aspect Oriented Programming via Proxy Pattern.

The Souce Generator I use works fine, and program compiles... but Solution Wide Analysis seems not to know there are automatic generated sources (as partial classes) and complains with a lot of errors.

Example:

I use nuget package Rop.ProxyGenerator

Example:

[ProxyOf("IHasOut","_controlIHasOut")]
public partial class WithHasOut : BaseControl, IHasOut
{
    private HasOutAop _controlHasOutAop=new HasOutAop();

}

Rop.ProxyGenerator generates automatically the AOP methods and properties using Proxy Pattern:

// Autogenerated code for Proxy class
namespace Test.Winforms
{
    public partial class ConUnOut
    {
        public virtual bool TryGetValue(int key, int value)
        {
            return _controlIHasOut.TryGetValue(key, value);
        }
     
    }
}

 

But Solution Wide Analysis doens't read this code, and complains that TryGetValue is not defined.

But I don't want to turn off Solution Wide Analysis... 

Any solution?

 

1
3 comments

Hello ramon, thank you for your question. Could you please check if you have a "pause" icon above the vertical scrollbar in the file with autogenerated code?

0

I'm also getting the same issues with solution wide analysis and source generated code, for example, while using nuget package OneOf.SourceGenerator

[GenerateOneOf]
public partial class NodeOrEdge<TNode> :
    OneOfBase<TNode, EdgeDefinition<TNode>>
    where TNode : notnull
{
}

Which generates the corresponding code

using System;

#pragma warning disable 1591

namespace GraphTest
{
    public partial class NodeOrEdge<TNode>
    {
        public NodeOrEdge(OneOf.OneOf<TNode, GraphFx.EdgeDefinition<TNode>> _) : base(_) { }

        public static implicit operator NodeOrEdge<TNode>(TNode _) => new NodeOrEdge<TNode>(_);
        public static explicit operator TNode(NodeOrEdge<TNode> _) => _.AsT0;

        public static implicit operator NodeOrEdge<TNode>(GraphFx.EdgeDefinition<TNode> _) => new NodeOrEdge<TNode>(_);
        public static explicit operator GraphFx.EdgeDefinition<TNode>(NodeOrEdge<TNode> _) => _.AsT1;
    }
}

In Visual Studio Code there is no error.

Also there is no pause icon above the vertical scroll bar on the generated code

 

0

Hello Iskander Sierra, thank you for your message.

Do I understand correctly that somewhere in other files you are getting a red code because of this? Do you have a chance to share a small sample solution so that we can reproduce the problem on our side? You can upload solution to JB server via https://uploads.jetbrains.com/ form.

Do I understand correctly that Visual Studio builds this solution without any problems?

Thank you!

0

Please sign in to leave a comment.