Linq - retrieving data dependent on the object type?

The example you give could be solved using OfType : IEnumerable items = ... var results = items.OfType() . OrderBy(x => x. Created).ToList() If you have to support combinations of properties that cross classes i.

E all items that have the IsDeadly property, you could use a combination of reflection to check the properties you want to use and dynamic to enable the duck typing you need, since technically these are different IsDeadly properties, you just know they should be treated the same in your scenario Doing that you can then assign the properties in your anonymous type dynamically. I.e. The following example returns results for all of your types that have the IsDeadly property: var results = items.

OrderBy(x => x. Created) . Where(x => x.GetType().

GetProperty("IsDeadly")! =null) . Select( x => { dynamic o = x; return new { IsDeadly = o.

IsDeadly, Created = o. Created }; }) .ToList() Also as @Henk Holterman pointed out, it only makes sense to return an enumeration of anonymous types where each property of the returned type makes sense / is defined for all the items in the enumeration.

The example you give could be solved using OfType: IEnumerable items = ... var results = items.OfType() . OrderBy(x => x. Created).ToList(); If you have to support combinations of properties that cross classes i.

E all items that have the IsDeadly property, you could use a combination of reflection to check the properties you want to use and dynamic to enable the duck typing you need, since technically these are different IsDeadly properties, you just know they should be treated the same in your scenario. Doing that you can then assign the properties in your anonymous type dynamically. I.e.

The following example returns results for all of your types that have the IsDeadly property: var results = items. OrderBy(x => x. Created) .

Where(x => x.GetType(). GetProperty("IsDeadly")! =null) .

Select( x => { dynamic o = x; return new { IsDeadly = o. IsDeadly, Created = o. Created }; }) .ToList(); Also as @Henk Holterman pointed out, it only makes sense to return an enumeration of anonymous types where each property of the returned type makes sense / is defined for all the items in the enumeration.

Where(x => x.GetType(). Return new { IsDeadly = o. IsDeadly, Created = o.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions