Ashish,
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". The compiler is not
able to use Type Inference to figure out the type parameter...
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
"Ashish" <as*****@thisisjunk.com> wrote in message
news:Og**************@TK2MSFTNGP10.phx.gbl...
| This is just a thought, may be its not possible , but is it possible to
| use generics in method declarations as return type arguments..
|
| for example
|
| public <T> Load(T value)
| {
| //method body
| }
|
| this would specify that the type passed would be type returned...
|
| so at compile time, the compiler would do a static type checking to see
| if there are compilation issues...
|
|
| for exampple
|
|
| Address addr = DataStore.Load(typeof(Address));
|
|
|
|