I am getting these errors with this code in the function Doit (I am running .Net 3.5):
Error 1: The best overloaded method match for 'LoadPref<A>(string, System.Func<string,A>, A)' has some invalid arguments
Error 2: Argument '2': cannot convert from 'method group' to 'System.Func<string,A>'
class A : SomeObject
{
}
static class Utilities
{
private T LoadPref<T>( string key, Func<string, T> loaderFunc, T defaultValue )
{
if ( Prefs.HasKey( key ) )
{
return loaderFunc( Prefs.GetString( key ) );
}
return defaultValue;
}
private T LoadAsset<T>( string assetPath ) where T : SomeObject
{
return (T)LoadAssetInSomeWay( assetPath );
}
private void Doit()
{
A asset = LoadPref<A>( "key", LoadAsset, null );
}
}
Anybody knows what’s wrong?
You need to change
LoadAssettoLoadAsset<A>for the generics to work properly.