What is the best way to merge two objects during runtime using C#?

后端 未结 7 522
野的像风
野的像风 2021-02-06 10:18

I have two objects and I want to merge them:

public class Foo
{
    public string Name { get; set; }
}

public class Bar
{
    public Guid Id { get; set; }
    p         


        
7条回答
  •  醉话见心
    2021-02-06 10:59

    Unfortunately, this is not something you can do easily. The best you can do is to create an anonymous type as part of a LINQ query, but that will have local scope only, and so will only be good for you in the method wherein you make it.

    When .NET 4 comes out, there's a new Dynamic Runtime Library that might help you out.

提交回复
热议问题