473,769 Members | 2,515 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 ApplicationLogi n(string userName, string
password, int dbId)

was called:

ApplicationLogi n("test","test" ,1);

I know that inside method ApplicationLogi n 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 3768
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(param s
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 "ApplicationLog in(...)"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.GetT ype();
System.Reflect ion.FieldInfo field = typeDescriptor. GetField("UserN ame");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(param s
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 "ApplicationLog in(...)"
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.GetT ype();
System.Reflect ion.FieldInfo field =

typeDescriptor. GetField("UserN ame");
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
23291
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
5772
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 would go something like this: dim qry as dao.querydef set qry = currentdb.querydefs("myquery") qry.parameters("Par1") = "blah"
7
9568
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 subroutine Let's say theres a sub that creates buttons and I want it to receive as a parameter the address of the sub that handles the OnClick event for the button being created How do I pass such a parameter Thanks in advance Richar
5
7463
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 used Object class as parameter. Now it can take any object as its parameter. But the problem is that I want to access the values of the private or public member variables of the passed object, for which I may have to typecast the Object class...
2
317
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
3826
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 DataKeyNames parameter of "UserCompany, BillableCompany". The DetailsView has control parameters for its select method pointing to these two keys on the GridView. But the select method function receives two copies of the UserCompany field! The...
4
5945
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? I use the Single.NaN to set the default values for some of my optional single arguments so that I can determine whether an argument was passed it ... but that does not work for booleans.
8
2703
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 which invites will target selected personnel among our customers via email. Each email will provide a custom hyperlink for each respondent using a SQL generated GUID value in the querystring. The GUID will be checked for validity before the user...
2
2493
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 value of one of the parameters that were passed to the method. Is this possible? Even if I have to use PInvoke to do so? I can currently find the parameter TYPEs using reflection but I can not figure out to obtain the values. Thanks,
0
9422
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10036
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8863
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6662
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5444
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.