Reflection Question

  • Thread starter Thread starter timothy
  • Start date Start date
T

timothy

Hi,

I have created a Delegate with EventArgs and I am trying to use reflection
to pick the correct EventArg. I have a combo box loaded with strings where
each represents an event arg for this delegate. I was hoping to make it
dynamic when the user selects the criteria in the combo box that I could
point to the correct event arg which I pass to the delegate. Should I use
reflection and how? Or is there a better way?

Thanks
 
Timothy,

This could be a problem. The reason for this is while you could list
all the classes that derive from EventArg in your list, you don't know that
you could necessarily construct an instance. You should probably filter the
list by ones that have a public default constructor.

Either that, or provide a mechanism for constructing the arguments to
pass to the constructor.

Hope this helps.
 
Thanks,

How about using an Enum instead?

Nicholas Paldino said:
Timothy,

This could be a problem. The reason for this is while you could list
all the classes that derive from EventArg in your list, you don't know that
you could necessarily construct an instance. You should probably filter the
list by ones that have a public default constructor.

Either that, or provide a mechanism for constructing the arguments to
pass to the constructor.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

timothy said:
Hi,

I have created a Delegate with EventArgs and I am trying to use reflection
to pick the correct EventArg. I have a combo box loaded with strings where
each represents an event arg for this delegate. I was hoping to make it
dynamic when the user selects the criteria in the combo box that I could
point to the correct event arg which I pass to the delegate. Should I use
reflection and how? Or is there a better way?

Thanks
 
Timothy,

You could, but what would that accomplish? You wouldn't have the name
of the class that you need to create, nor would you have the information
about creating instances of it.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

timothy said:
Thanks,

How about using an Enum instead?

message news:%[email protected]...
Timothy,

This could be a problem. The reason for this is while you could list
all the classes that derive from EventArg in your list, you don't know that
you could necessarily construct an instance. You should probably filter the
list by ones that have a public default constructor.

Either that, or provide a mechanism for constructing the arguments to
pass to the constructor.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

timothy said:
Hi,

I have created a Delegate with EventArgs and I am trying to use reflection
to pick the correct EventArg. I have a combo box loaded with strings where
each represents an event arg for this delegate. I was hoping to make it
dynamic when the user selects the criteria in the combo box that I could
point to the correct event arg which I pass to the delegate. Should I use
reflection and how? Or is there a better way?

Thanks
 
Back
Top