---
title: "Access a property of IEnumerable"  
description: "Access a property of IEnumerable"  
author: "Jayden Bell"  
published: 2014-01-28  
updated: 2014-01-29  
canonical: https://www.mindstick.com/forum/1900/access-a-property-of-ienumerable  
category: "c#"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Access a property of IEnumerable

I have a custom [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp) for a [combobox](https://www.mindstick.com/articles/57/display-record-according-to-combobox-selection-in-csharp-dot-net) having following [properties](https://www.mindstick.com/articles/23331/nootropics-7-different-types-and-their-unique-properties):

```
public IEnumerable<object> ItemsSource{    get { return (IEnumerable<object>)GetValue(ItemsSourceProperty); }    set    {        SetValue(ItemsSourceProperty, value);    }}public string DisplayMemberPath{    get { return (string)GetValue(DisplayMemberPathProperty); }    set { SetValue(DisplayMemberPathProperty, value); }}
```

where ItemsSourceProperty,DisplayMemberPathProperty are the [dependency](https://www.mindstick.com/interview/23013/what-is-dependency-resolution) properties [already](https://yourviews.mindstick.com/view/88453/the-hidden-ways-ai-is-already-controlling-your-daily-life) registered.

Now if ItemSource has a list of [custom objects](https://answers.mindstick.com/qa/34009/truncating-custom-objects-in-salesforce) :{id int, name [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp)}. and DisplayMemberPath has value:'name' or 'id'. How can I [access](https://www.mindstick.com/articles/12994/how-foreigners-can-access-blocked-websites-in-china) 'name' or 'id' properties of my object ?

## Replies

### Reply by Pravesh Singh

Hi Jayden,\

It's not entirely clear why you need to do this binding yourself (when WPF does a lot of this for you), but this might work:

```
foreach (object item in ItemsSource){    var property = item.GetType().GetProperty(DisplayMemberPath);    var value = property.GetValue(item, null);    // Use the value here}
```

Note that this will be pretty slow, and will only handle a single property name (rather than a full path). There are more complex alternatives which would perform better, but I'd probably go with the simplest approach first.


---

Original Source: https://www.mindstick.com/forum/1900/access-a-property-of-ienumerable

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
