473,400 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

how to detect parameter values passed to method

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
Jul 19 '05 #1
2 3735
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 theobject. This is done using Reflection. If the method "ApplicationLogin(...)"updated member fields in the containing class you could interrogate theinstance of that class to get the values of those member fields.
To do this, you use Reflection to get a descriptor object of the parameteryou 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 werepassed in on the method call via reflection. If you want to save them, youneed to persist them in a database or a business entity object (i.e. abusiness data storage object) for further use.

Hope this helps,
Luke Venediger.


Jul 19 '05 #2
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" <ma****@nospam.pl> wrote in message
news:07****************************@phx.gbl...
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.

Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Noozer | last post by:
Is it possible to detect where on a page the click occurred when the OnClick event of the BODY tag is fired? Thx
21
by: Marc DVer | last post by:
I am trying to create a query that can be loaded as a querydef object but not having to assign values to the parameters if I don't want to. Normally when using a parameter query in VBA my code...
7
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
5
by: Ram | last post by:
Hi Friends I want to develope a custom control in .net which can be used with any project. I am writing a function in that class which I want to take any object as parameter. For that I have...
2
by: Marcin | last post by:
Hello! Is there any method to detect parameters values passed to called method? For example: public Guid ApplicationLogin(string userName, string password, int dbId)
2
by: Damon | last post by:
Help! Need this fixed ASAP. I have a GridView/DetailsView master/details form set up, with both bound to separate ObjectDataSource objects. Both the GridView and the DetailsView have a...
4
by: Joe HM | last post by:
Hello - I realize that there is no more IsMissing function in VB.NET but how can I have a boolean argument that is optional and in the code I need to determine whether it was passed it or not? ...
8
by: Alec MacLean | last post by:
Hi, I'm using the DAAB Ent Lib (Jan 2006) for .NET 2.0, with VS 2005 Pro. My project is a Web app project (using the WAP add in). Background: I'm creating a survey system for our company, for...
2
by: ME | last post by:
How would one obtain the parameter VALUES of a method that has already run? I can find the method using the StackTrace and StackFrame classes but once I find the method I would like to obtain the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.