Click here to Skip to main content
15,896,606 members
Home / Discussions / C#
   

C#

 
AnswerRe: Is there is some feature in C# that will act like #Define in C++ ??? Pin
PIEBALDconsult8-Aug-07 5:48
mvePIEBALDconsult8-Aug-07 5:48 
QuestionProblem- Server Busy...Switch/Retry Pin
Iftekhar Naim8-Aug-07 2:04
Iftekhar Naim8-Aug-07 2:04 
QuestionReflection, Invoking Methods Pin
glFrustum8-Aug-07 2:01
glFrustum8-Aug-07 2:01 
AnswerRe: Reflection, Invoking Methods Pin
kubben8-Aug-07 2:27
kubben8-Aug-07 2:27 
GeneralRe: Reflection, Invoking Methods Pin
glFrustum8-Aug-07 3:08
glFrustum8-Aug-07 3:08 
GeneralRe: Reflection, Invoking Methods Pin
kubben8-Aug-07 3:16
kubben8-Aug-07 3:16 
GeneralRe: Reflection, Invoking Methods Pin
glFrustum8-Aug-07 4:08
glFrustum8-Aug-07 4:08 
AnswerRe: Reflection, Invoking Methods Pin
J4amieC8-Aug-07 3:32
J4amieC8-Aug-07 3:32 
glFrustum wrote:
I'm looking for a nicer way to invoke methods. The following code is called by:
Fetch(someObject, "GetCustomer", 1).

The ugly thing about this is that the name of the method is passed as a string. Is there a way to support something like:
Fetch(someObject.GetCustomer, 1)?


Im still searching for the reason why you think the latter is preferable to the former. In answer to your question, if all the methods you want to call from your Fetch method have the same signature you could use delegates insstead of reflection (which identifies methods/properties the same way you do - by name).

eg. Say this is a data layer you are writing and the Fetch method is responsible for getting data from a vasiety of methods which follow this signature:

DataSet SomeGetDataMethod(object [] parameters)

you would define a delegate along the lines of

public delegate DataSet GetDataDelegate(object[] parameters);

You would then define your Fetch method as follows

public DataSet Fetch(GetDataDelegate method, object[] parameters)
{
   // you could async invoke the method here. This is sync for illustration
   method.Invoke(parameters);
}


Then to call this method you could have:

object[] parameters = new object{ 1 };<br />
Fetch( new GetDataDelegate(someObject.GetCustomer), parameters)


you could then pass a delegate to any of your data methods into this fetch method without using reflection.






Personally id stick with reflection!


GeneralRe: Reflection, Invoking Methods Pin
glFrustum8-Aug-07 4:00
glFrustum8-Aug-07 4:00 
GeneralRe: Reflection, Invoking Methods Pin
J4amieC8-Aug-07 4:43
J4amieC8-Aug-07 4:43 
GeneralRe: Reflection, Invoking Methods [modified] Pin
glFrustum8-Aug-07 4:47
glFrustum8-Aug-07 4:47 
QuestionHow to Split one big excel file in to smaller files? Pin
Guru_yogi8-Aug-07 1:37
Guru_yogi8-Aug-07 1:37 
AnswerRe: How to Split one big excel file in to smaller files? Pin
Justin Perez8-Aug-07 2:32
Justin Perez8-Aug-07 2:32 
GeneralRe: How to Split one big excel file in to smaller files? Pin
Guru_yogi8-Aug-07 2:59
Guru_yogi8-Aug-07 2:59 
GeneralRe: How to Split one big excel file in to smaller files? Pin
Justin Perez8-Aug-07 4:04
Justin Perez8-Aug-07 4:04 
QuestionDatagridview Pin
lesoftrons8-Aug-07 1:25
lesoftrons8-Aug-07 1:25 
AnswerRe: Datagridview [modified] Pin
Blue_Boy8-Aug-07 1:48
Blue_Boy8-Aug-07 1:48 
QuestionMessage Queue Error Pin
M. J. Jaya Chitra8-Aug-07 1:24
M. J. Jaya Chitra8-Aug-07 1:24 
AnswerRe: Message Queue Error Pin
Pete O'Hanlon8-Aug-07 1:35
mvePete O'Hanlon8-Aug-07 1:35 
GeneralRe: Message Queue Error Pin
M. J. Jaya Chitra8-Aug-07 1:50
M. J. Jaya Chitra8-Aug-07 1:50 
AnswerRe: Message Queue Error Pin
kubben8-Aug-07 2:32
kubben8-Aug-07 2:32 
GeneralRe: Message Queue Error Pin
M. J. Jaya Chitra8-Aug-07 2:51
M. J. Jaya Chitra8-Aug-07 2:51 
GeneralRe: Message Queue Error Pin
kubben8-Aug-07 2:59
kubben8-Aug-07 2:59 
GeneralRe: Message Queue Error Pin
M. J. Jaya Chitra8-Aug-07 3:13
M. J. Jaya Chitra8-Aug-07 3:13 
GeneralRe: Message Queue Error Pin
kubben8-Aug-07 3:21
kubben8-Aug-07 3:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.