If your types share a base class or interface, you can constrain your method to that interface, and access members of the interface directly.
If they are unrelated types of
T, then you might want to consider using a separate method overload for each type. This is far more maintainable than the mess that arises from checking the types inside of a method and handling each type individually.
That being said, you might want to consider just using Linq's
Select method instead of your own
Select is intended for mapping operations - converting data from one form to another.
- Verify type, properties of Linq object with T anonymous parameter in function
- When selecting an anonymous type with LINQ from EF, is there no way to run a method on an object as you select it?
- LINQ Project properties into a new anonymous type with Contains
- Linq Groupby multiple columns with the same name (An anonymous type cannot have multiple properties with the same name)
- Setting all properties of dynamic object in anonymous type in linq query
- Linq GroupBy Anonymous Type with Dynamic Properties
- how to group by over anonymous type with vb.net linq to object
- linq and json, anonymous type cannot have multiple properties with the same name
- LINQ select query with Anonymous type and user Defined type
- C# re-use LINQ expression for different properties with same type
- How can I set properties on all items from a linq query with values from another object that is also pulled from a query?
- How to assign a nullable int property in an anonymous type in LINQ with a Union?
- C# LINQ build expression with anonymous type
- LINQ OrderBy anonymous object with projection comparer
- Anonymous Type with Linq and Guid
- LINQ query with GROUP BY and Count(*) into Anonymous Type
- LINQ - Contains with anonymous type
- Linq to entities - SQL Query - Where list contains object with 2 properties (or more)
- Expression tree to initialize new anonymous object with arbitrary number of properties
- linq query anonymous type cannot be converted to POCO object
- Passing object of anonymous type as parameter to a method
- C# Create object with dynamic properties : LINQ select List<object> values by property names array
- How to write LINQ query with column name as parameter still in a type safe way
- Linq with where clause in many-to-many EF Code First object
- Combine object properties into a list with LINQ
- Linq - Using GroupBy with my own type vs anonymous type
- LINQ include nested properties when selecting anonymous type
- Using SelectedItem property of ComboBox with Linq Anonymous Type
- Linq to sql as object data source - designer problem with partial classes
- Pass linq anonymous object to function
- Iterate every combination of two elements in HashSet
- EF Core updating foreign key is not updating the navigation property
- Expressions anonymous type
- Filtering a List of SelectListItem to create list SelectList with unique values
- LINQ query OrderBy doesn't work
- Sort a LINQ with another LINQ in MVC
- How to not get repeated names appeared in the Combo Box c#
- c# Linq Oracle convert long to string for join
- How to write this SQL average query in linq
- Populate a list of Objects (With Linq?)
- JSON.net linq can not select node with where statement
- Is there a Visual Studio editor feature to split a page vertically for Linq commenting?
- default(T?) does not return null when T is a value type
- How to intersect in-memory data with data from database
- Using a strongly typed method as an argument without specifying parameters
- Why does Linq ignore my where clause?
- Using LINQ How to access values of List item inside a Class
- Include, select nested objects not returning
- Datatable Linq GroupBy, Aggregate Count
- How to get the child declaring type from an expression?