-
Notifications
You must be signed in to change notification settings - Fork 15
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
feat(Functional): add With extension method #45
Conversation
I like what you have done so far, but as it stands this will only work with mutable types. It would be useful if it could match getter properties to constructor parameters. Is that possible with reflection? I've never looked into it, so that may not be possible. What I'm thinking is that for the following type: class Contrived
{
public Contrived(int a, int b) => (A, B) = (a, b);
public int A { get };
public int B { get };
public int C { get; set; }
} Then |
Yes, my first objective was to make it work with POCO. I will write some tests with get only properties and specialized constructor and see if I can adapt the code to make it work. |
@DavidArno I updated my code based on your request. I am now using the most relevant constructor instead of the default one. The only restriction of the code is that you should named your constructor parameter correctly or it won't work. About performance issues, I think we can drastically improve the methods by caching information we receive from |
Not sure why this isn't showing as merged, but it is. I've added it to the v3.1 branch. Now I just need to find time to update the docs and release. 😀 |
Closing as Github hasn't detected the merge (probably due to me doing things wrongly). |
@DavidArno Well, I think you merged it manually (with your computer) and not using the website. I think it's a bad behavior because you did merge the code but the website shows you refused it. Moreover, it is easier to merge using the website by changing the target branch in the PR settings. https://github.com/blog/2224-change-the-base-branch-of-a-pull-request |
Thanks for the tip. That wouldn't have worked in this case though. Completely my fault. Apologies. |
@DavidArno Ok. No problem. Do you have a release date for the next version? |
I don't, unfortunately. I'm aiming for next week, but no promises. Looking through the code, I have a suggestion. Both Are you happy with that? |
@DavidArno That sounds great. |
Linked to #44
Based on this stackoverflow post (https://stackoverflow.com/questions/3445784/copy-the-property-values-to-another-object-with-c-sharp), I started to work on the
With
extension method.I added two methods :
Copy
to create a news immutable object andWith
by reusing the previous method to create a new immutable object and adding new properties.