thanks Mattias, I am using params object[] to dynamically log runtime value.
Following is the sample code. Please let me know if you think any other
better approach to solve this issue. Arif
////////////////////Sample code/////////////////////////////////
class Class1
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
//Sample One
int val = 10;
string name = "Arif";
BusinessFunctio n1(val,name);
//Sampe Two
int b = 10;
string name2 ="Test";
bool check = true;
BusinessFunctio n2(b,name2,chec k);
}
static void BusinessFunctio n1(int val, string name)
{
LogTrace(val,na me);
}
static void BusinessFunctio n2(int b, string name2, bool check)
{
LogTrace(b,name 2,check);
}
public static void LogTrace(params object[] args)
{
StackTrace callStack = new StackTrace(1, true);
StackFrame callingMethodFr ame = callStack.GetFr ame(0);
if (args == null || args.Length == 0)
{
Console.WriteLi ne("no parameters");
}
else
{
MethodBase callingMethod = callingMethodFr ame.GetMethod() ;
ParameterInfo[] parameters = callingMethod.G etParameters();
int inParamCount = parameters.Leng th;
foreach (ParameterInfo parameter in parameters)
if (parameter.IsOu t) inParamCount--;
Debug.Assert(in ParamCount == args.Length, String.Format(" Incorrect
number of arguments. Expected {0} but was {1}.", parameters.Leng th,
args.Length));
int paramCount = parameters.Leng th;
int argIndex = 0;
for (int i = 0; i < paramCount; i++)
{
Console.WriteLi ne(parameters[i].Name);
if (parameters[i].IsOut)
Console.WriteLi ne("<Unknown>") ;
else
{
if (args[argIndex] == null)
Console.WriteLi ne("<null>");
else
{
Console.WriteLi ne(args[argIndex].ToString().Tri m());
}
argIndex++;
}
if (i < paramCount - 1)
Console.WriteLi ne(",");
}
}
}
}
"Mattias Sjögren" wrote:
but not sure if if it's possible to retreive
runtime passed in actual parameter values in .net 1.1 ?
Not without explicitly naming them.
Mattias
--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.