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
As others have pointed out, there is no way to "merge" them (if you're thinking of a select *
with multiple tables in SQL, for example). Your closest analog would be taking the route that Zxpro has provided and "group" them in a generic class.
What, exactly, would you want to accomplish with "merging" them, though? Declaring the properties explicitly would have the biggest convenience effect on writing code and compile-time safety, but if you can't specify a type then there's no opportunity for that. If you're just looking for a generic "property bag" container, then an existing data structure, such as a Dictionary
or Hashtable
should be able to handle that.