By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,695 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,695 IT Pros & Developers. It's quick & easy.

unknow return type

P: n/a
How can you set that a function returns a type, but you don't know it from
before?

voidunknow Function() ?
unknow Function()?

Thx
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
object?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
How can you set that a function returns a type, but you don't know it from
before?

voidunknow Function() ?
unknow Function()?

Thx

Nov 15 '05 #2

P: n/a
Thx,

Now I have got this problem, I want to search the type
when i found it, i need to do the Run() method of that object

But it isn't possible: C:\Documents and Settings\Eindwerk\Mijn
documenten\BARCO\Eindwerk\Project
Files\thuis\13december\Aviewerversie02\FileLoad.cs (401): 'object' does not
contain a definition for 'Run'
So I need a solution, because I know that that object has the type which has
a run........ But C# doens't like it.......

Help me
Thx
JC

"Miha Markic" <miha at rthand com> schreef in bericht
news:ul**************@TK2MSFTNGP12.phx.gbl...
object?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
How can you set that a function returns a type, but you don't know it from before?

voidunknow Function() ?
unknow Function()?

Thx


Nov 15 '05 #3

P: n/a
You need to get involved in some design work. If you are sure (because of
your design) that whatever "unknown" object is returned has a "Run" method,
then you should cast to the appropriate type and then call the Run method. I
would use an interface to do this. You probably need to read up on this
stuff a bit. Check www.msdn.com and www.gotdotnet.com, www.codeproject.com,
etc.

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:Ok**************@TK2MSFTNGP10.phx.gbl...
Thx,

Now I have got this problem, I want to search the type
when i found it, i need to do the Run() method of that object

But it isn't possible: C:\Documents and Settings\Eindwerk\Mijn
documenten\BARCO\Eindwerk\Project
Files\thuis\13december\Aviewerversie02\FileLoad.cs (401): 'object' does not
contain a definition for 'Run'
So I need a solution, because I know that that object has the type which has a run........ But C# doens't like it.......

Help me
Thx
JC

"Miha Markic" <miha at rthand com> schreef in bericht
news:ul**************@TK2MSFTNGP12.phx.gbl...
object?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
How can you set that a function returns a type, but you don't know it from before?

voidunknow Function() ?
unknow Function()?

Thx



Nov 15 '05 #4

P: n/a
"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:Ok**************@TK2MSFTNGP10.phx.gbl...
Thx,

Now I have got this problem, I want to search the type
when i found it, i need to do the Run() method of that object

But it isn't possible: C:\Documents and Settings\Eindwerk\Mijn
documenten\BARCO\Eindwerk\Project
Files\thuis\13december\Aviewerversie02\FileLoad.cs (401): 'object' does not
contain a definition for 'Run'
So I need a solution, because I know that that object has the type which has a run........ But C# doens't like it.......


Create an interface for all your objects that will have a run method, then
check if the returned object implements that interface, and if so, cast it
and execute it:

// Class
public myRunableClass : IRun
{
// class stuff her
}
// Interface
public interface IRun
{
public void Run();
}
// Code

// code here that returns "h" cast as an object

if (h is IRun) // If h implements IRun
{
// Cast to IRun (which will have just one method and no properties, as
defined in the interface above)
// and call Run() on cast object
((IRun)h).Run();
}

HTH
--
Daisy The Cow
Nov 15 '05 #5

P: n/a
One of two solutions:

1) use Interfaces. Create an interface that contains the Run method - let's
call it IRunnable for an example. Then all your objects that use a Run
method would Implement the IRunnable interface. Now, your function can
return a variable of IRunnable type (and many object types potentially can
be returned as long as they implement this interface). You will now be able
to call the Run method from the function return.

2) use Reflection (System.Reflection namespace). Use the GetType method on
the object returned, and then use one of the InvokeMember overloads to call
the Run function.

From a purely elegance-of-structure point of view, and from a performance
point of view, (1) is the preferred choice.

-Rob Teixeira [MVP]

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:Ok**************@TK2MSFTNGP10.phx.gbl...
Thx,

Now I have got this problem, I want to search the type
when i found it, i need to do the Run() method of that object

But it isn't possible: C:\Documents and Settings\Eindwerk\Mijn
documenten\BARCO\Eindwerk\Project
Files\thuis\13december\Aviewerversie02\FileLoad.cs (401): 'object' does not
contain a definition for 'Run'
So I need a solution, because I know that that object has the type which has a run........ But C# doens't like it.......

Help me
Thx
JC

"Miha Markic" <miha at rthand com> schreef in bericht
news:ul**************@TK2MSFTNGP12.phx.gbl...
object?

--
Miha Markic - RightHand .NET consulting & development
miha at rthand com

"Jeroen Ceuppens" <je*************@barco.com> wrote in message
news:uT**************@tk2msftngp13.phx.gbl...
How can you set that a function returns a type, but you don't know it from before?

voidunknow Function() ?
unknow Function()?

Thx



Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.