KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I want to make a method: object Execute() { return type.InvokeMember(..); } to accept a generic parameter: T Execute<T>() { return Execute() as T; /* doesn't work: The type parameter 'T' cannot be used with the 'as' operator because it does not have a class type constraint nor a 'class' constraint */ // also neither typeof(T), nor T.GetType() are possible return (T) Execute(); // ok } But I think operator as will be very useful: if result type isn't T method will return null , instead of an exception! Is it possible to do?
Tags (comma-separated)
Save Edits
Cancel