I think you want to try to filter an arbitrary Enumerable of MembershipUser into a local List. Your filter should therefore be type Func<IEnumerable<MembershipUser>, List<MembershipUser>>
. In addition one thing is missing: this list that you are trying to filter. This must be passed as a parameter to the filter when you call it. I assume it is passed as a parameter, but it could just as easily be another internal variable or property of your class.
This results in the following function (see below for full working sample):
void FindType(Func<IEnumerable<MembershipUser>, List<MembershipUser>> filter, IEnumerable<MembershipUser> list)
{
Users = filter(list);
}
Something I learned from my functional programming courses in university: get your types correct first then the rest will follow. Think about what you are trying to do in terms of inputs and outputs. Not only for your functions, but also for your lambdas. (Which essentially are nameless functions).
Full working sample:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Sample d = new Sample();
IEnumerable<MembershipUser> ll = new List<MembershipUser>()
{
new MembershipUser() { Name ="1", IsApproved=false},
new MembershipUser() { Name ="2", IsApproved=true},
};
d.FindType(members => members.Where(m => m.IsApproved).ToList(), ll);
Console.WriteLine(d.Users.Count());
}
class MembershipUser
{
public string Name
{get;set;}
public bool IsApproved
{get;set;}
}
class Sample
{
private List<MembershipUser> users;
public void FindType(Func<IEnumerable<MembershipUser>, List<MembershipUser>> filter, IEnumerable<MembershipUser> list)
{
users = filter(list);
}
public List<MembershipUser> Users
{
get { return users; }
}
}
}
}