Brad,
As the other have shown you can define a method with a parameterized return
type.
Yes you can define a generic function where the parameter is only used for
the return type.
public T doSomething<T where T:new()>()
However! You need to supply the type parameter when you call the method
directly, something like:
object o = doSomething<object>();
MemoryStream m = doSomething<MemoryStream>();
However! it "violates" an FxCop rule as its "ambiguous".
Here is a thread that discusses it:
http://groups.google.com/group/micro...4e46ca8f99b798
Personally I find in the case of GetCustomAttribute (as the thread shows) it
makes sense as the type parameter is encapsulating the downcast, plus the
type parameter is used to "do work".
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"Brad Wood" <bradley|.wood|@ndsu|.edu> wrote in message
news:eY**************@tk2msftngp13.phx.gbl...
| It doesn't look like something like this is possible in 2.0:
| public <T> doStuff();
|
| Am I correct, and if so, there's probably a good reason that I can't
| think of why not...