Given the following lines of code in C#:
var testvalue = result[0]
.GetType()
.GetProperty(propertyNameToFilterOn)
.GetValue(result[0], null);
var test = result
.Where(x => x
.GetType()
.GetProperty(propertyNameToFilterOn)
?.GetValue(x, null) == "46ee6799-2bed-4a7a-93f8-0839affbd218")
.ToList();
result obviously contains a collection of objects. The first line gives me a value (46ee6799-2bed-4a7a-93f8-0839affbd218). However, the second line returns 0 objects in the list. The first line confirms that the first object in the collection does have the value I'm filtering on in the second line, while the second line tells me that no objects in the collection has that value on the property I'm checking. Can someone explain why this does not work? And potentially provide an alternative?
Aucun commentaire:
Enregistrer un commentaire