Search code examples
c#silverlightgenericsdelegates

Casting Func<T> to Func<object>


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>


Solution

  • This will do the trick:

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