POCO helper class refactoring I have a helper class that I am using to return the selected items in a number of IEnumerable POCO collection but I'm not happy with the implementation. One of the reasons for using this method is that the collections area returned by RIA services as ReadOnlyObservableCollections and I don't believe they support LINQ but may be wrong.

Is there a way to refactor these three methods using generics?
Are there any other improvements that I can make?

public class ModelHelper : IModelHelper
{
    public IList&lt;Int32&gt; GetSelectedResults(IEnumerable&lt;FaultAuditScoresDto&gt; scores)
    {
        IList&lt;Int32&gt; selected = new List&lt;Int32&gt;();

        foreach (FaultAuditScoresDto s in scores)
        {
            if (s.IsSelected)
            {
                selected.Add(s.ID);
            }
        }

        return selected;
    }

    public IList&lt;Int32&gt; GetSelectedResults(IEnumerable&lt;ZonesDto&gt; zones)
    {
        IList&lt;Int32&gt; selected = new List&lt;Int32&gt;();

        foreach (ZonesDto s in zones)
        {
            if (s.IsSelected)
            {
                selected.Add(s.ID);
            }
        }

        return selected;
    }

    public IList&lt;Int32&gt; GetSelectedResults(IEnumerable&lt;FaultAreasDto&gt; faultAreas)
    {
        IList&lt;Int32&gt; selected = new List&lt;Int32&gt;();

        foreach (FaultAreasDto s in faultAreas)
        {
            if (s.IsSelected)
            {
                selected.Add(s.ID);
            }
        }

        return selected;
    }
}


I have refactored it to use generics and a dynamic type for the loop but I'm still not happy with it

     public IList&lt;T&gt; GetSelectedResults&lt;T,U&gt;(IEnumerable&lt;U&gt; scores)
    {
        List&lt;T&gt; selected = new List&lt;T&gt;();

        foreach (dynamic s in scores)
        {
            if (s.IsSelected)
            {
                //Need to cast the ID as &lt;T&gt; due to the IList limitation below
                //http://connect.microsoft.com/VisualStudio/feedback/details/534288/ilist-dynamic-cannot-call-a-method-add-without-casting
                selected.Add((T)s.ID);
            }
        }
        return selected;
    }


Any other idea?
Implement this interface in all of your Dto where it needed:

interface ICommonDtoStuff&lt;T&gt;
{
    bool IsSelected { get; }
    T ID { get; }
}


Then you can create a method like this:

public IList&lt;T&gt; GetSelectedResults&lt;T, U&gt;(IEnumerable&lt;U&gt; scores) where U : ICommonDtoStuff&lt;T&gt;
{
    return scores.Where(x =&gt; x.IsSelected).Select(x =&gt; x.ID).ToList();
}


As extension method:

public static class Extensions
{
    public static IList&lt;T&gt; GetSelectedResults&lt;T&gt;(this IEnumerable&lt;ICommonDtoStuff&lt;T&gt;&gt; scores)
    {
        return scores.Where(x =&gt; x.IsSelected).Select(x =&gt; x.ID).ToList();
    }
}