PC Review


Reply
Thread Tools Rate Thread

how to detect parameter values passed to method

 
 
Marcin
Guest
Posts: n/a
 
      5th Aug 2003
Hello!

Is there any method to detect parameters values passed to
called method?

For example:

public Guid ApplicationLogin(string userName, string
password, int dbId)

was called:

ApplicationLogin("test","test",1);

I know that inside method ApplicationLogin I can detect
what method was called
and what parameters it has using object StackFrame:

StackFrame sf = new StackFrame(0);
sf.GetMethod().GetParameters() - list of parameters

But how can I detect those parameters value?
Anybody have any ideas?

Thanks

Marcin
 
Reply With Quote
 
 
 
 
Marcin
Guest
Posts: n/a
 
      6th Aug 2003
Thank you for help - but in my case i don't store
parameter values in called object fields so i can't
retrieve them using reflection.

I want to write generic function which takes parameters
passed to any method and then use reflection method Invoke
to call another method with the same parameters.

I need something like access to parameters declared with
params keyword (f.e. method declaration: UseParams(params
int[] list) ), but that must work with method that use
standard parameters (without params keyword).

I don't even know if it's possible, but maybe somone knows
the answer.

Thanks

Marcin

>-----Original Message-----
>Hi there,
>
>You can get the value of fields in an object if you have

an instance of the
>object. This is done using Reflection. If the

method "ApplicationLogin(...)"
>updated member fields in the containing class you could

interrogate the
>instance of that class to get the values of those member

fields.
>
>To do this, you use Reflection to get a descriptor object

of the parameter
>you want to look up. In this case, it will be describing
>MyCustomClass.UserName. Of course, you start with the

System.Type object.
>
>To get your field:
>
>System.Type typeDescriptor = myInstance.GetType();
>System.Reflection.FieldInfo field =

typeDescriptor.GetField("UserName");
>string userName = (string) field.GetValue(myInstance);
>
>As an aside, I'm not sure why you'd want to interrogate

the values that were
>passed in on the method call via reflection. If you want

to save them, you
>need to persist them in a database or a business entity

object (i.e. a
>business data storage object) for further use.
>
>Hope this helps,
>Luke Venediger.
>


 
Reply With Quote
 
Luke Venediger
Guest
Posts: n/a
 
      6th Aug 2003
Hi Marcin,

It is possible to have a generic method that takes in an array of parameters
(using params keyword in your method signature) and invoke a method on an
object. You'll need a way to determine which method you want to invoke,
either by passing in a method name or by counting the number of input
parameters you receive and matching them to a method signature in the target
object.

It is only possible to write a generic scalar method if you have a fixed
number of arguments, and a way to determine which method to call based on
some ID or indicator. You will need to pass all arguments in the
lowest-common-denominator type, which in most cases is System.Object.

Either way, the concept of a generic method is not a good one, it will make
your code path unclear and could also lead to maintenance problems in the
future.

Hope that helps,
Luke Venediger.

"Marcin" <(E-Mail Removed)> wrote in message
news:077801c35bf1$c606db90$(E-Mail Removed)...
> Thank you for help - but in my case i don't store
> parameter values in called object fields so i can't
> retrieve them using reflection.
>
> I want to write generic function which takes parameters
> passed to any method and then use reflection method Invoke
> to call another method with the same parameters.
>
> I need something like access to parameters declared with
> params keyword (f.e. method declaration: UseParams(params
> int[] list) ), but that must work with method that use
> standard parameters (without params keyword).
>
> I don't even know if it's possible, but maybe somone knows
> the answer.
>
> Thanks
>
> Marcin
>
> >-----Original Message-----
> >Hi there,
> >
> >You can get the value of fields in an object if you have

> an instance of the
> >object. This is done using Reflection. If the

> method "ApplicationLogin(...)"
> >updated member fields in the containing class you could

> interrogate the
> >instance of that class to get the values of those member

> fields.
> >
> >To do this, you use Reflection to get a descriptor object

> of the parameter
> >you want to look up. In this case, it will be describing
> >MyCustomClass.UserName. Of course, you start with the

> System.Type object.
> >
> >To get your field:
> >
> >System.Type typeDescriptor = myInstance.GetType();
> >System.Reflection.FieldInfo field =

> typeDescriptor.GetField("UserName");
> >string userName = (string) field.GetValue(myInstance);
> >
> >As an aside, I'm not sure why you'd want to interrogate

> the values that were
> >passed in on the method call via reflection. If you want

> to save them, you
> >need to persist them in a database or a business entity

> object (i.e. a
> >business data storage object) for further use.
> >
> >Hope this helps,
> >Luke Venediger.
> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Soap method namespace prefix prevents values from being passed correctly HolmerJohn@gmail.com Microsoft ASP .NET 0 30th Oct 2007 02:50 PM
Obtain parameter values from method ME Microsoft Dot NET 2 22nd Sep 2007 04:25 AM
Obtain parameter values from method ME Microsoft C# .NET 2 22nd Sep 2007 04:25 AM
Excel2000: Reading values from range, passed to function as parameter using an expression Arvi Laanemets Microsoft Excel Programming 3 29th Apr 2005 02:34 PM
Re: how to detect parameter values passed to method Chris Capel Microsoft C# .NET 1 6th Aug 2003 09:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:38 AM.