Value of parameters 
Author Message
 Value of parameters

Hi

Is it possible to get the value of method parameter via System.Reflection?
We are using logger classes and it would be useful to get the parameter
value automatically. The System.Reflection.ParameterInfo[] doesn't include
the value of the parameter. Is there another way than the Relection to get
these values?

Regards
Thomas



Fri, 03 Dec 2004 19:22:18 GMT  
 Value of parameters
Thomas,

    Not really, and it doesn't make sense.  You would have to have a hook
into the method when it is called to determine this information.  For
example, if I have a method like this:

public void Foo(int number)

    I can find out that number is an integer, but to find the value passed
to it, I would have to have a stack created.  The only way to tap into the
stack right now would be to hook into the .NET runtime (which you have
instantiated yourself).  But if no one is calling the method at the time,
then it doesn't make sense.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Hi

> Is it possible to get the value of method parameter via System.Reflection?
> We are using logger classes and it would be useful to get the parameter
> value automatically. The System.Reflection.ParameterInfo[] doesn't include
> the value of the parameter. Is there another way than the Relection to get
> these values?

> Regards
> Thomas



Fri, 03 Dec 2004 20:21:37 GMT  
 Value of parameters
hello thomas.

 with the refrection you can get the signature of the method, there is not
way you can get the value of the parameter, at least with out the
intervention of the called function, if you can modify the function or
inherit from the class and override the function then you are ok. otherwise
there is not much point in do what you ask for.

--
Ignacio Machin
Senior System Analyst.
Bitcore, Inc.
Miami, FL 33172


Quote:
> Hi

> Is it possible to get the value of method parameter via System.Reflection?
> We are using logger classes and it would be useful to get the parameter
> value automatically. The System.Reflection.ParameterInfo[] doesn't include
> the value of the parameter. Is there another way than the Relection to get
> these values?

> Regards
> Thomas



Fri, 03 Dec 2004 20:33:42 GMT  
 Value of parameters
Ignacio

I'm using the following method to create the parameter string:
protected string GetParameterString( System.Reflection.ConstructorInfo
constructorInfo )

{

string delimiter = "";

StringBuilder returnValue = new StringBuilder("( ");

System.Reflection.ParameterInfo[] parameters =
constructorInfo.GetParameters();

for (int i=0; i<parameters.Length;i++)

{

returnValue.Append(delimiter);

returnValue.Append(parameters[i].ParameterType.ToString());

returnValue.Append(" ");

returnValue.Append(parameters[i].Name);

delimiter = ", ";

Quote:
}

returnValue.Append(" )");

return returnValue.ToString();

Quote:
}

The output in my logfile looks like this:
2002-06-17 13:22:21,676 [7944] DEBUG AdressmodulWebServices [] <> -
ACAG.AdressmodulWebServices.WsAdressArt, FillDataSet ( System.String
sessionKey )

It would be very interesting to know the value of the parameter sessionKey.

We use in every method some of the calls for the logger, so it's only a
switch in the config file to enable the trace. It would be helpful to find
bugs in the application.

Regards
Thomas


Quote:
> hello thomas.

>  with the refrection you can get the signature of the method, there is not
> way you can get the value of the parameter, at least with out the
> intervention of the called function, if you can modify the function or
> inherit from the class and override the function then you are ok.
otherwise
> there is not much point in do what you ask for.

> --
> Ignacio Machin
> Senior System Analyst.
> Bitcore, Inc.
> Miami, FL 33172



> > Hi

> > Is it possible to get the value of method parameter via
System.Reflection?
> > We are using logger classes and it would be useful to get the parameter
> > value automatically. The System.Reflection.ParameterInfo[] doesn't
include
> > the value of the parameter. Is there another way than the Relection to
get
> > these values?

> > Regards
> > Thomas



Fri, 03 Dec 2004 21:01:44 GMT  
 Value of parameters
Have you try using the Trace object?

I think is the best in your case, from my point of view what I would do is
something like:

1 - Use Trace object, this is the best, easiest way to do what you want

2- Custom logging
- Create a class containing the logging/profiling code ( I would prefer the
use of a static method for this. )
- use [Conditional] attribute for define when compile this code or not.

Hope this help.

--
Ignacio Machin
Senior System Analyst.
Bitcore, Inc.
Miami, FL 33172


Quote:
> Ignacio

> I'm using the following method to create the parameter string:
> protected string GetParameterString( System.Reflection.ConstructorInfo
> constructorInfo )

> {

> string delimiter = "";

> StringBuilder returnValue = new StringBuilder("( ");

> System.Reflection.ParameterInfo[] parameters =
> constructorInfo.GetParameters();

> for (int i=0; i<parameters.Length;i++)

> {

> returnValue.Append(delimiter);

> returnValue.Append(parameters[i].ParameterType.ToString());

> returnValue.Append(" ");

> returnValue.Append(parameters[i].Name);

> delimiter = ", ";

> }

> returnValue.Append(" )");

> return returnValue.ToString();

> }

> The output in my logfile looks like this:
> 2002-06-17 13:22:21,676 [7944] DEBUG AdressmodulWebServices [] <> -
> ACAG.AdressmodulWebServices.WsAdressArt, FillDataSet ( System.String
> sessionKey )

> It would be very interesting to know the value of the parameter
sessionKey.

> We use in every method some of the calls for the logger, so it's only a
> switch in the config file to enable the trace. It would be helpful to find
> bugs in the application.

> Regards
> Thomas



> > hello thomas.

> >  with the refrection you can get the signature of the method, there is
not
> > way you can get the value of the parameter, at least with out the
> > intervention of the called function, if you can modify the function or
> > inherit from the class and override the function then you are ok.
> otherwise
> > there is not much point in do what you ask for.

> > --
> > Ignacio Machin
> > Senior System Analyst.
> > Bitcore, Inc.
> > Miami, FL 33172



> > > Hi

> > > Is it possible to get the value of method parameter via
> System.Reflection?
> > > We are using logger classes and it would be useful to get the
parameter
> > > value automatically. The System.Reflection.ParameterInfo[] doesn't
> include
> > > the value of the parameter. Is there another way than the Relection to
> get
> > > these values?

> > > Regards
> > > Thomas



Fri, 03 Dec 2004 22:10:12 GMT  
 Value of parameters
The base for our logging is log4net, which you'll find on sourceforge.net.
Most of our requirements is implementet, some more information would be
nice, like the value of parameters....

Regards
Thomas


Quote:
> Have you try using the Trace object?

> I think is the best in your case, from my point of view what I would do is
> something like:

> 1 - Use Trace object, this is the best, easiest way to do what you want

> 2- Custom logging
> - Create a class containing the logging/profiling code ( I would prefer
the
> use of a static method for this. )
> - use [Conditional] attribute for define when compile this code or not.

> Hope this help.

> --
> Ignacio Machin
> Senior System Analyst.
> Bitcore, Inc.
> Miami, FL 33172



> > Ignacio

> > I'm using the following method to create the parameter string:
> > protected string GetParameterString( System.Reflection.ConstructorInfo
> > constructorInfo )

> > {

> > string delimiter = "";

> > StringBuilder returnValue = new StringBuilder("( ");

> > System.Reflection.ParameterInfo[] parameters =
> > constructorInfo.GetParameters();

> > for (int i=0; i<parameters.Length;i++)

> > {

> > returnValue.Append(delimiter);

> > returnValue.Append(parameters[i].ParameterType.ToString());

> > returnValue.Append(" ");

> > returnValue.Append(parameters[i].Name);

> > delimiter = ", ";

> > }

> > returnValue.Append(" )");

> > return returnValue.ToString();

> > }

> > The output in my logfile looks like this:
> > 2002-06-17 13:22:21,676 [7944] DEBUG AdressmodulWebServices [] <> -
> > ACAG.AdressmodulWebServices.WsAdressArt, FillDataSet ( System.String
> > sessionKey )

> > It would be very interesting to know the value of the parameter
> sessionKey.

> > We use in every method some of the calls for the logger, so it's only a
> > switch in the config file to enable the trace. It would be helpful to
find
> > bugs in the application.

> > Regards
> > Thomas



> > > hello thomas.

> > >  with the refrection you can get the signature of the method, there is
> not
> > > way you can get the value of the parameter, at least with out the
> > > intervention of the called function, if you can modify the function or
> > > inherit from the class and override the function then you are ok.
> > otherwise
> > > there is not much point in do what you ask for.

> > > --
> > > Ignacio Machin
> > > Senior System Analyst.
> > > Bitcore, Inc.
> > > Miami, FL 33172



> > > > Hi

> > > > Is it possible to get the value of method parameter via
> > System.Reflection?
> > > > We are using logger classes and it would be useful to get the
> parameter
> > > > value automatically. The System.Reflection.ParameterInfo[] doesn't
> > include
> > > > the value of the parameter. Is there another way than the Relection
to
> > get
> > > > these values?

> > > > Regards
> > > > Thomas



Fri, 03 Dec 2004 22:31:37 GMT  
 Value of parameters
Hi Thomas.

Reflection can reflect what in the metadata. The value of the parameter is
not part of the metadata so Reflection is suitable for this situation.

The eaiest way to get the value is within the function call itself. Is
there any reason we cannot output the value within the called function?



Sun, 05 Dec 2004 23:54:26 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. function parameters: default value, optional parameter

2. Default values for parameters?

3. function templates without <T> as return value or parameter

4. Method Output Parameter vs Return Value

5. template template parameter with default value (VS.NET 2003)

6. Values as template parameters (compiler bug?)

7. Generic object as method parameter / return value?

8. Function parameter default value?

9. Parameter default values

10. Emulate Named Parameters and Default Values

11. default parameter values

12. Reflection & Parameter Values

 

 
Powered by phpBB® Forum Software