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

Result object typechecking #3

Closed
Ciberusps opened this issue Mar 20, 2019 · 1 comment
Closed

Result object typechecking #3

Ciberusps opened this issue Mar 20, 2019 · 1 comment
Labels

Comments

@Ciberusps
Copy link

Not sure if its possible in C# but what about

var result = TypeMerger<ResultTypeDto>.Merge(obj1, obj2);

If merged type not equal with "ResultTypeDto" cause an error(not sure how to implement it mb via language specific things mb VS Code extension/VS extension)

Use case:

public class ProductWithSalesPersonDto: IProduct {
    public SalesPerson: string;
}
...
var someProducts = 
    from products in _context.Product
    from users in _context.Users
    where products.IsPublished == true || products.UserId == userId
    orderby products.UpdatedAt
    select TypeMerger.TypeMerger<ProductWithSalesPersonDto>.Merge (products, new { users.SalesPerson });
@kfinley
Copy link
Owner

kfinley commented Mar 20, 2019

I may be reading this wrong but I think what you're asking is if the TypeMerger could return something other than an Anonymous Type. In this situation you'd like to use TypeMerger to merge the selected Product and the projection from the Users set.

If that is the case I would say you should look at AutoMapper. This opens up a big question of why should you use TypeMerger instead of just using AutoMapper using the CreateMissingTypeMaps property. My thoughts on this is because if you went that route you'd have to write more code in order to configure the mapping. With TypeMerger it's a zero configuration call to merge any two Anonymous Types.

Let me know if that answers your question.

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

No branches or pull requests

2 participants