Reputation:
Is it possible to write an inline generic method? For example, how can I translate the below method into an inline delegate.
public TUser Current<TUser>() where TUser : User
{
return getCurrentUser() as TUser;
}
Even just being able to call
Func<User> userFunc = new Func<User>(Current<User>);
would be useful.
Upvotes: 2
Views: 911
Reputation: 131676
You can use a lambda expression in C# 3.0:
Func<User> userFunc = () => getCurrentUser() as User;
or
Func<User> userFunc = Current<User>;
Upvotes: 3