Closed alec-anikin closed 4 years ago
Just to be sure, the expected mapping code should be as follows?
public partial class Mapper : Test.IMapper
{
public virtual SomeClass Map(SomeClass other)
{
return new Protobuf.SomeClass(someStruct: other.SomeStruct);
}
}
For project declared structs now mapping is
public partial class Mapper : Protobuf.IMapper
{
public virtual SomeClass Map(SomeClass other)
{
return new Protobuf.SomeClass(someStruct: new Protobuf.SomeStruct(value: other.SomeStruct.Value));
}
}
I think both versions are correct: someStruct: new Protobuf.SomeStruct(value: other.SomeStruct.Value)
or someStruct: other.SomeStruct
but the second one is simpler especially for multiple constructors cases.
@alec-anikin can you show the definition of the Point
structure? The version from the external library. Does it contain fields or properties?
I've just tested it with MappingGenerator.OnBuildGenerator 1.13.329 and SmartCodeGenerator.Engine 1.2.9 and I've got the mapping code as follows
// ------------------------------------------------------------------------------
// <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>
// ------------------------------------------------------------------------------
using System;
using System.Diagnostics;
using System.Drawing;
using MappingGenerator.OnBuildGenerator;
using System.Linq;
using ConsoleApp11;
namespace ConsoleApp11
{
[System.CodeDom.Compiler.GeneratedCode("MappingGenerator.OnBuildGenerator.OnBuildMappingGenerator", "1.13.329.0")]
public partial class Mapper : ConsoleApp11.IMapper
{
public virtual SomeClass Map(SomeClass other)
{
return new ConsoleApp11.SomeClass(someStruct: new Point(x: other.SomeStruct.X, y: other.SomeStruct.Y));
}
}
}
It looks like it's working as expected. Can you send me a solution that reproduces that problem?
OnBuildGenerator-Example-master.zip It sounds very strange but just add reference to another project from solution and generated code will be broken. May be two or more paths to the same type in the project is the cause.
Ok, I'm able to reproduce the issue but it completely doesn't make any sense to me. Removing reference to Lib project fixes the issue. I need to take a look closer to what's going there.
It looks like Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace
(which is used for loading projects) doesn't play very well with netstandard
projects. I've made a small test by replacing MSBuildWorkspace
with https://github.com/daveaglick/Buildalyzer#roslyn-workspaces and it seems to solve the issue but I don't know what the ramifications could be. I need to run a couple more tests to make sure that there are no negative side effects.
Waiting for response https://github.com/daveaglick/Buildalyzer/issues/130
@alec-anikin
A new version of SmartCodeGenerator.Engine
has been released. Please update the SmartCodeGenerator.Engine
package and verify if it works correctly.
Solved with https://github.com/cezarypiatek/SmartCodeGenerator/pull/4
It works fine! Thank you!
Hi!
It works fine for structs declared in solution but not for external structs. VS2019, SDK 3.1.102
How to reproduce:
Generated mapping
Thank you!