I've been struggling with a delegate problem. I am sending a method as a parameter, which don't get parameter and returns generic type Result<T>.
public Result<Content> GetContents()
{
var contents = new Result<List<TypeLibrary.Content>>();
contents.Object = context.GetContents();
if (contents.Object != null)
{
contents.Success = true;
}
else
{
contents.Success = false;
}
return contents;
}
public static Result<T> Invoker<T>(Func<Result<T>> genericFunctionName) where T : new()
{
Result<T> result;
try
{
//do staff
result = genericFunctionName();
}
catch (Exception)
{
throw;
}
return result;
}
model is
public class Result<T> where T : new()
{
public bool Success { get; set; }
public string Message { get; set; }
public T Object { get; set; }
public Result()
{
Object = new T();
}
}
usage is
var result = InvokerHelper.Invoker(_content.GetContents());
but I get
The type arguments for method
InvokerHelper.Invoker<T>(System.Func<TypeLibrary.Base.Result<T>>) cannot be inferred from the usage. Try specifying the type arguments explicitly.
while compiling.
What is wrong with that?