Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

netstandard 2.0 compile #655

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Jojoshua
Copy link

@Jojoshua Jojoshua commented Nov 3, 2023

No description provided.

@andrerav
Copy link
Contributor

andrerav commented Nov 4, 2023

Thanks @Jojoshua, I will take a look. At first glance it seems the test suite failed, but I haven't taken a closer look yet. Did you run the tests locally?

@DocSvartz
Copy link

DocSvartz commented Nov 4, 2023

@andrerav For it to work, also need to remove all links to MapsterDynamic.
and install from nuget Microsoft.CSharp in MapsterCore

not Working map to interface

and this tests
TestMapFromSecondSourceObject()
TestIMapFrom_WhenMethodImplemented()
TestIMapFrom_WhenMethodIsNotImplemented()

But this strange the specified code was also supported by netstandard2.0
But for some reason it shows on the local machine. What is not available in netstandard2.0

AssemblyBuilder
FieldBuilder
ILGenerator
MethodBuilder
PropertyBuilder

Now in official doc it only support beginning from netstandard2.1

@DocSvartz
Copy link

DocSvartz commented Nov 4, 2023

This will work without global refactoring the code.
With preprocessor directives.
But only when targeting to NetFramework 4.8 or 4.7 possible.
i checked on local machine with 4.8 all build and test green

IMapFrom dont working

@Jojoshua
Copy link
Author

Jojoshua commented Nov 4, 2023

Thanks @Jojoshua, I will take a look. At first glance it seems the test suite failed, but I haven't taken a closer look yet. Did you run the tests locally?

@andrerav I didn't run any tests locally. I only had 30 mins yesterday with a goal to make it build without errors.

It went smooth except for the one method I had to comment out for imap because default method interfaces are not supported. I feel like this is could be easily changed when I understand what it's for.

This was my first look at the codebase, I will try to give this another 30 today and run the tests. If anyone can get tests working before I get to it feel free.

@DocSvartz
Copy link

DocSvartz commented Nov 4, 2023

@Jojoshua You get Mapster.dll for netstandart 2.0 after compile.

upd:
i get dll for netstandart 2.0
I didn't see that it is necessary to install this


<ItemGroup>
    <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
    <PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
  </ItemGroup>

@Jojoshua
Copy link
Author

Jojoshua commented Nov 4, 2023

@Jojoshua You get Mapster.dll for netstandart 2.0 after compile.

upd: i get dll for netstandart 2.0 I didn't see that it is necessary to install this


<ItemGroup>
    <PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
    <PackageReference Include="System.Reflection.Emit" Version="4.7.0" />
  </ItemGroup>

The project wouldn't compile for me without adding those. System.Reflection.Emit has netstandard 2.0 support but if you don't require it standalone it's going to want to pull it from net6/7.

@Jojoshua
Copy link
Author

Jojoshua commented Nov 4, 2023

@andrerav Ok, tests are now passing for me locally. Does the PR automatically run the tests or do you need to execute it?

@DocSvartz
Copy link

DocSvartz commented Nov 5, 2023

@andrerav How do you see Mapster's public api extension strategy?

  1. Support only available functionality to target framework
  2. Support only functionality that will be on all target framework

I asked this question to understand Is there any need for an implementation for IMapFrom in netstandard 2.0 build.
IMapFrom not work in netstandard 2.0 because support for default interface implementation was introduced only starting with netstandard 2.1.

Without targeting Maspter to net 6.0. IMapFrom just wouldn't exist.

@andrerav
Copy link
Contributor

andrerav commented Nov 6, 2023

@DocSvartz @Jojoshua IMapFrom was added as a new feature in 7.4.0 (see #533). It's perfectly fine to leave this out from a netstandard2.0-compatible version of Mapster in my opinion. It's impossible for anyone to have put that interface to use in that user group :) We can add a note about this in the documentation.

@Jojoshua
Copy link
Author

Jojoshua commented Nov 6, 2023

@DocSvartz @Jojoshua IMapFrom was added as a new feature in 7.4.0 (see #533). It's perfectly fine to leave this out from a netstandard2.0-compatible version of Mapster in my opinion. It's impossible for anyone to have put that interface to use in that user group :) We can add a note about this in the documentation.

That makes sense. With that in mind perhaps the PR is good to go? Could you try running the tests again?

@andrerav
Copy link
Contributor

andrerav commented Nov 6, 2023

@DocSvartz @Jojoshua The tests passed, so this looks promising :) I will check that the packaging works as expected before merging, but I don't expect any problems.

@DocSvartz
Copy link

DocSvartz commented Nov 6, 2023

@andrerav @Jojoshua This is what I said, that the tests will pass. But they only test for Net 6.0. and Net 7.0. If you create a separate group of tests. Which will be target at net 4.8 (max support netstandard 2.0) for example, then the ImapFrom test will not pass

In the created library to netstandard 2.0 this code will be cut out and accordingly. There is simply nothing to work there :)


#if  NET6_0_OR_GREATER
    public void ConfigureMapping(TypeAdapterConfig config)
    {
        config.NewConfig(typeof(TSource), GetType());
    }
#endif

I want to say that testing in net 7.0 does not guarantee that it will also work in netstandard 2.0
(in relation to functions using mechanisms from the new version of the framework (netstandard 2.1 and higher).
It rather shows that functions that were written earlier do not change their behavior in a newer framework.

@DocSvartz
Copy link

I am writing this more as a warning to the author that he could potentially get behavior that he did not expect. If he uses it where he wanted (an environment where there is access only to the netstandard 2.0 ). Because the tests do not use the target library for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants