Alex Rivera | Logout

Casting Func<T> to Func<object>

Asked 2011-07-08T12:58:29.387
23

I'm trying to figure out how to pass Func<T> to Func<object> method argument:

public void Foo<T>(Func<T> p) where T: class
{
    Foo(p);
}

public void Foo(Func<object> p)
{

}

Strange thing, it works in NET 4.0 Class library, but doesn't work in Silverlight 4 Class library. Actually I want it to work in Silverlight, and I have input parameters like Func<T, bool>

Edit
Report

1 Answer

31

This will do the trick:

public void Foo<T>(Func<T> p) where T : class
{
    Func<object> f = () => p();
    Foo(f);
}
answered 2011-07-08T13:00:09.177

Your Answer