Is there a way to get the values of the paramaters to a
method programatically ?
I know that I can use reflection to find out the
parameter names and types, etc., but I want to know the
values of those parameters too.
I'm trying to write a generic error handler. I wan't to
be able to log the values that caused the error, without
the user of the class having to specify the values 'cause
they're lazy ;)
Thanks,
Brad 7 3682
Hi Brad,
Parameters have value only inside the body of the function (at run time).
Reflection won't help here.
B\rgds
100
"Brad Quinn" <br********@yah oo.com> wrote in message
news:01******** *************** *****@phx.gbl.. . Is there a way to get the values of the paramaters to a method programatically ?
I know that I can use reflection to find out the parameter names and types, etc., but I want to know the values of those parameters too.
I'm trying to write a generic error handler. I wan't to be able to log the values that caused the error, without the user of the class having to specify the values 'cause they're lazy ;)
Thanks, Brad
On Wed, 12 Nov 2003 10:29:22 -0800, Brad Quinn wrote: Is there a way to get the values of the paramaters to a method programatically ?
I know that I can use reflection to find out the parameter names and types, etc., but I want to know the values of those parameters too.
I'm trying to write a generic error handler. I wan't to be able to log the values that caused the error, without the user of the class having to specify the values 'cause they're lazy ;)
Thanks, Brad
MethodBase.GetC urrentMethod() returns the method that you're inside right
now. From there you can move on to get all the params to it including
values.
--
Roy Osherove
weblog: http://www.iserializable.com
StackFrame has a method named GetMethod() that returns a
MethodBase.
MethodBase has a method named GetParameters() that
returns a ParameterInfo [].
The problem is that ParameterInfo (understandably ) does
not contain the values.
However, there must be references to the parameters on
the call stack. I should think that there might be a way
to get at them, possibly through the StackFrame.
I was hoping that ArgIterator might help, but I can't
figure out how to intialize one (don't know how to get a
RuntimeArgument Handle).
Thanks anyway. -----Original Message----- On Wed, 12 Nov 2003 10:29:22 -0800, Brad Quinn wrote:
MethodBase.Get CurrentMethod() returns the method that
you're inside rightnow. From there you can move on to get all the params to
it includingvalues. -- Roy Osherove weblog: http://www.iserializable.com .
If you really want to do this, you received some good answers already.
I feel that this is bad architectural practice because it obscures what is
really happening in the error handlers, and it adds unnecessary complexity
to the code base.
The axim "Just because you can do something doesn't mean you should do it"
applies farily often to reflection - keep it simple.
Eric
"Brad Quinn" <br********@yah oo.com> wrote in message
news:01******** *************** *****@phx.gbl.. . Is there a way to get the values of the paramaters to a method programatically ?
I know that I can use reflection to find out the parameter names and types, etc., but I want to know the values of those parameters too.
I'm trying to write a generic error handler. I wan't to be able to log the values that caused the error, without the user of the class having to specify the values 'cause they're lazy ;)
Thanks, Brad
I did a lot of research following this question, and there's no way to do it
using .net.
Only way to go is :
- hijack in the debugging sdk and attach a debugger to the process to get
the parameter values.
- intercept calls using message sinks and contextboumd objects
- know in advance your parameters.
Arguments are not on the "call stack" but on the "stack" itself, so you
can't really walk that stack yourself.
--
Sebastien Lambla http://thetechnologist.is-a-geek.com/blog/
"Brad Quinn" <an*******@disc ussions.microso ft.com> a écrit dans le message
de news: 00************* *************** @phx.gbl... StackFrame has a method named GetMethod() that returns a MethodBase.
MethodBase has a method named GetParameters() that returns a ParameterInfo [].
The problem is that ParameterInfo (understandably ) does not contain the values.
However, there must be references to the parameters on the call stack. I should think that there might be a way to get at them, possibly through the StackFrame.
I was hoping that ArgIterator might help, but I can't figure out how to intialize one (don't know how to get a RuntimeArgument Handle).
Thanks anyway.
-----Original Message----- On Wed, 12 Nov 2003 10:29:22 -0800, Brad Quinn wrote:
MethodBase.Get CurrentMethod() returns the method that you're inside rightnow. From there you can move on to get all the params to it includingvalues. -- Roy Osherove weblog: http://www.iserializable.com .
Thanks,
That's what I thought. -----Original Message----- I did a lot of research following this question, and
there's no way to do itusing .net.
Only way to go is : - hijack in the debugging sdk and attach a debugger to
the process to getthe parameter values. - intercept calls using message sinks and contextboumd
objects- know in advance your parameters.
Arguments are not on the "call stack" but on the "stack"
itself, so youcan't really walk that stack yourself.
-- Sebastien Lambla http://thetechnologist.is-a-geek.com/blog/
"Brad Quinn" <an*******@disc ussions.microso ft.com> a
écrit dans le messagede news: 00************* *************** @phx.gbl... StackFrame has a method named GetMethod() that returns
a MethodBase.
MethodBase has a method named GetParameters() that returns a ParameterInfo [].
The problem is that ParameterInfo (understandably ) does not contain the values.
However, there must be references to the parameters on the call stack. I should think that there might be a
way to get at them, possibly through the StackFrame.
I was hoping that ArgIterator might help, but I can't figure out how to intialize one (don't know how to get
a RuntimeArgument Handle).
Thanks anyway.
>-----Original Message----- >On Wed, 12 Nov 2003 10:29:22 -0800, Brad Quinn wrote: > > >MethodBase.Get CurrentMethod() returns the method that you're inside right >now. From there you can move on to get all the params
to it including >values. >-- >Roy Osherove >weblog: http://www.iserializable.com >. >
.
I'm trying to keep things as simple as possible.
Obviously, for any particular method I know the
parameters. Suppose I have a method like this;
public int Compute( int a, int b )
{
try {
return a * b;
} catch ( Exception ex ) {
Log.Write( ex, string.Format( "a={0}, b={1}", a,
b ) );
throw;
}
}
When an exception is thrown I log the exception and the
parameters to the method, ignoring the fact that (in
general) member variables may have contributed to the
exception.
Now suppose that the method is changed, but that the lazy
programmer forgets to update the logging statement
public int Compute( int a, int b, int c )
{
try {
return a * b * c;
} catch ( Exception ex ) {
Log.Write( ex, string.Format( "a={0}, b={1}", a,
b ) );
throw;
}
}
If we look at the logs, we might be confused as to why
the exception is being thrown. I'm trying to make error
logging simpler (for the consumer).
Thanks for your concern. -----Original Message----- If you really want to do this, you received some good
answers already. I feel that this is bad architectural practice because
it obscures what isreally happening in the error handlers, and it adds
unnecessary complexityto the code base.
The axim "Just because you can do something doesn't mean
you should do it"applies farily often to reflection - keep it simple.
Eric
"Brad Quinn" <br********@yah oo.com> wrote in message news:01******* *************** ******@phx.gbl. .. Is there a way to get the values of the paramaters to a method programatically ?
I know that I can use reflection to find out the parameter names and types, etc., but I want to know the values of those parameters too.
I'm trying to write a generic error handler. I wan't
to be able to log the values that caused the error,
without the user of the class having to specify the
values 'cause they're lazy ;)
Thanks, Brad
. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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: Julia |
last post by:
Hi,
I have been asked this before but I think that I didn't explain myself well
I am using exception and logging and I would like to log the parameters
which was passed to the function
whenever an exception was occurred,again,I want to emphasize that I am the
owner of the code.
I can see that idlasm can view the content of an assembly so I wonder why my
|
by: Mike Dinnis |
last post by:
Hi,
I've been working through a number of turorials to try to learn more about
retrieving data from a SQL database. I think i've mastered techniques where
i create a sql string in the page and pass it to the Db and retrieveing data
from a stored procedure, but I can't get the hang of parameters.
I have a method where I can get the parameters passed to the sp but it
doesn't want to return any results. Here's a copy of my code:
|
by: Martin Raychev |
last post by:
Hi all,
I have the following problem:
I have a private method that returns a SqlDataReader. For this to work I
have not to close the DB connection in the above method. I do this only to
|
by: kplkumar |
last post by:
I am trying to get the method and the parameters passed to that method
from the stackTrace.
My code is,
private void GetExecutingMethodInfo()
{
StackTrace trace = new StackTrace(false);
for (int index = 0; index < trace.FrameCount; ++index)
| |
by: cody |
last post by:
I got a similar idea a couple of months ago, but now this one will require
no change to the clr, is relatively easy to implement and would be a great
addition to C# 3.0 :)
so here we go..
To make things simpler and better readable I'd make all default parameters
named parameters so that you can decide for yourself which one to pass and
which not, rather than relying on massively overlaoded methods which
hopefully provide the best...
|
by: Aaron Gray |
last post by:
I put together the following code to get the href's parameters :-
function GetParameters()
{
var arg = new Object();
var href = document.location.href;
if ( href.indexOf( "?") != -1)
{
var params = href.split( "?");
|
by: preeti13 |
last post by:
Hi friends i have a probelm i am try to pass the value to the employeeid parameter but getting th error please help me how i can do this i am getting the error here is my code
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
|
by: preeti13 |
last post by:
Hi guys i am here with my another probelm please help me.trying insert the value into the data base but getting the null value error .I am getting thsi error
Cannot insert the value NULL into column 'EmployeeID', table 'Accomplishments.dbo.Accomplishment'; column does not allow nulls. INSERT fails. The statement has been terminated.
and my code is this
using System;
using System.Collections;
|
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: 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: 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...
|
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: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |