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 2 3770
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.
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 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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
|
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"
|
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
|
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...
|
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)
| |
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...
|
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.
|
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...
|
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,
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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...
|
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |