passing void to another class and execute it

F

Frank Uray

Hi all

I have a strange question ... :))

I would like to build a generic class for executing
voids. The void or a pointer of a void should
be passed to this class.

Is this possible without writing dynamic C# code ?

Regards
Frank Uray
 
P

Peter Duniho

Frank said:
Hi all

I have a strange question ... :))

I would like to build a generic class for executing
voids. The void or a pointer of a void should
be passed to this class.

I don't understand the question at all. What does it mean to "execute a
void"?
Is this possible without writing dynamic C# code ?

What do you mean by "dynamic C# code"? Are you specifically talking
about the new C# 4.0 feature, the "dynamic" type? Or something else?

Pete
 
F

Family Tree Mike

Hi all

I have a strange question ... :))

I would like to build a generic class for executing
voids. The void or a pointer of a void should
be passed to this class.

Is this possible without writing dynamic C# code ?

Regards
Frank Uray

Do you mean delegates? Like in the following?

namespace ConsoleApplication1
{
delegate void MyChoice();

class Program
{
static void CallMeOne()
{
Console.WriteLine("You're a one!");
}

static void CallMeTwo()
{
Console.WriteLine("You are too!");
}

static void Foo(MyChoice m)
{
m();
}

static void Main(string[] args)
{
MyChoice m1 = CallMeOne;
Foo(m1);

MyChoice m2 = CallMeTwo;
Foo(m2);

Console.WriteLine("Done");
Console.ReadKey();
}
}
}
 
F

Frank Uray

Hi Pete

Well, I just want to call (or execute) a given void.

Pseudo code like this:

ExecuteClass local_ExecuteClass = new ExecuteClass();
local_ExecuteClass.GivenVoid = ref to some local Void
In the ExecuteClass I then like to call this "ref to some local Void".

With dynamic code I mean to write code within a string
and create a Assembly from this string, compile it while Runtime
and execute the method in it.

Regards
Frank Uray
 
P

Peter Duniho

Frank said:
Hi Pete

Well, I just want to call (or execute) a given void.

Those are practically the exact words you posted originally. They don't
have any more meaning now than they did then.
Pseudo code like this:

ExecuteClass local_ExecuteClass = new ExecuteClass();
local_ExecuteClass.GivenVoid = ref to some local Void

First, you should really stop using that naming convention. It makes
your code very hard to read, and adds nothing useful.

Second, what does "ref to some local Void" mean? What's a "void"? C#
doesn't have "void *", so what do you really mean here?
In the ExecuteClass I then like to call this "ref to some local Void".

You can call a method or invoke a delegate. Is "ref to some local Void"
a method? A reference to a delegate? Or something else?
With dynamic code I mean to write code within a string
and create a Assembly from this string, compile it while Runtime
and execute the method in it.

You should almost never ever have to resort to something like that.
But, unless you can explain your question better, I cannot rule out that
that might be the only possible solution.

Pete
 
F

Frank Uray

Hi Anja

Thanks about your replay.

I knew about delegates, but I was not sure
if I can use it in my case.
The article was helping, thanks.

Best regards
Frank Uray


Anja Länge said:
Peter said:
I don't understand the question at all. What does it mean to
"execute a void"?

I think he is asking for delegates but doesn't know them ;)

Frank, if I am right, you could start here:

[delegate]
http://msdn.microsoft.com/en-us/library/900fyy8e(VS.71).aspx

[Delegates Tutorial]
http://msdn.microsoft.com/en-us/library/aa288459(VS.71).aspx


Anja


.
 
F

Frank Uray

Hi Mike

Thanks a lot for your replay !

Best regards
Frank Uray

Family Tree Mike said:
Hi all

I have a strange question ... :))

I would like to build a generic class for executing
voids. The void or a pointer of a void should
be passed to this class.

Is this possible without writing dynamic C# code ?

Regards
Frank Uray

Do you mean delegates? Like in the following?

namespace ConsoleApplication1
{
delegate void MyChoice();

class Program
{
static void CallMeOne()
{
Console.WriteLine("You're a one!");
}

static void CallMeTwo()
{
Console.WriteLine("You are too!");
}

static void Foo(MyChoice m)
{
m();
}

static void Main(string[] args)
{
MyChoice m1 = CallMeOne;
Foo(m1);

MyChoice m2 = CallMeTwo;
Foo(m2);

Console.WriteLine("Done");
Console.ReadKey();
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top