troubleshooting Question

How to return inherited class types from function?

Avatar of Skale
Skale asked on
.NET ProgrammingC#
4 Comments1 Solution28 ViewsLast Modified:
I'm having a problem (in fact it is not an issue I can direct cast or safe cast) about one structure.

I have classes like below: All Class1 to Class5 inherited from ClassA and I have one function which is not created by myself returns type ClassA. Now I wonder is there any way to return any of the inherited (Class1,..., Class5) type desired class?

This is the function that cannot be modified because it comes from the COM interface

public ClassA GetMyObject(){...}
Now I would like to put in a function that I create and return my desired type is it possible? Or do you suggest anything different?

public <T> GetMyObjectCustom(<T> DesiredReturnFormat){(<T>) GetMyObject()}
ASKER CERTIFIED SOLUTION
AndyAinscow
Freelance programmer / Consultant

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros