-
-
Notifications
You must be signed in to change notification settings - Fork 155
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
Support From
and To
static factory methods
#1117
Comments
I'm not sure to what you are referring by IMO the following signatures could be supported (all ordinary, non-async methods returning
I'd split them across two Hints for a contribution despite the contributing documentation:
|
Some system types contain Also, in a naive implementation, |
@TonEnfer thanks for your input, very valuable! |
It seems to me that Also, I can't predict the consequences of calling static ResultsBenchmarkDotNet v0.14.0, Windows 11 (10.0.26100.2314)
Codepublic class ExplicitCastVsToByte
{
[Params(1000)]
public int _count;
private decimal[] _data;
[GlobalSetup]
public void Setup()
{
_data = new decimal[_count];
for (var i = 0; i < _count; i++)
{
_data[i] = new Random().Next() % 255;
}
}
[Benchmark(Baseline = true)]
public byte[] ExplicitCast()
{
var result = new byte[_data.Length];
for (var i = 0; i < _data.Length; i++)
{
result[i] = (byte)_data[i];
}
return result;
}
[Benchmark]
public byte[] ToByte()
{
var result = new byte[_data.Length];
for (var i = 0; i < _data.Length; i++)
{
result[i] = decimal.ToByte(_data[i]);
}
return result;
}
}
public class ExplicitCastVsToDouble
{
[Params(1000)]
public int _count;
private decimal[] _data;
[GlobalSetup]
public void Setup()
{
_data = new decimal[_count];
for (var i = 0; i < _count; i++)
{
_data[i] = new Random().Next() % 255;
}
}
[Benchmark(Baseline = true)]
public double[] ExplicitCast()
{
var result = new double[_data.Length];
for (var i = 0; i < _data.Length; i++)
{
result[i] = (double)_data[i];
}
return result;
}
[Benchmark]
public double[] ToDouble()
{
var result = new double[_data.Length];
for (var i = 0; i < _data.Length; i++)
{
result[i] = decimal.ToDouble(_data[i]);
}
return result;
}
} I don't have enough experience writing this kind of code to be sure that these benchmarks even test what they are supposed to. But if their results are to be believed, then the performance of calling static methods is almost the same as with explicit casting. The other side of the issue is the possible behavioral inconsistencies that would be introduced by such a code change. What do you think about this? |
If we place the |
When I was looking at the code that might be related to the implementation of this new functionality, I had the following question. Currently, This situation is reproduced, for example, in the following case: It seemed to me that it would be more logical to call this method with For |
Currently, Mapperly aims to handle nullable reference types (NRTs) flexibly, especially within the |
Thanks for all the clarifications. I plan to work on this feature, but I'm not sure I'll have enough time to do it well enough to share it with the community. |
Thank you for your willingness to contribute to Mapperly! I've assigned the issue to you 😊. If you find you don’t have the time to work on it, feel free to unassign yourself. Don’t hesitate to reach out if you have any questions! |
Hi @latonz |
Fixes for code review
Is your feature request related to a problem? Please describe.
Many objects provide static methods instead of constructors for semantic reasons. Unfortunately as Mapperly is unable to use them users have to manually provide wrapper methods. Based upon.
Solution
Mapperly should look for static methods that meet the following criteria:
Implementation
From
methods before looking for the sourceTo
methods.To
methods could include non static methods.See #1107.
The text was updated successfully, but these errors were encountered: