Consider the following method:
TOTAL(string v, params Object[] c)
Called with the following values :
A, {B, {C, {D,E},F}
or (as a 'structured' array layout) :
A,
[0] B
[1] ----- [0] C
----- [1] ------ [0] D
------ [1] E
----- [2] F
When this method gets called (via reflection) for the first time. The
value of 'c' is:
[0] --- [0] B
--- [1] ---- [0] C ...etc.etc.
But subsequent calls (with _exaclty_ the same values) result in a value
of 'c' of:
[0] B
[1] ---- [0] C ...etc. etc.
The method (TOTAL) is also called between the calls with the same set
of values.
I miss one level! Is this by design or am I missing something? If it is
by design, what's the use of doing it this way? 5 1282
papa.c...@gmail.com wrote: Consider the following method: TOTAL(string v, params Object[] c)
Called with the following values : A, {B, {C, {D,E},F}
or (as a 'structured' array layout) :
<snip>
That certainly sounds odd. Could you post a short but complete program
which demonstrates the problem? See http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
that.
Jon
Made a mistake with the values; here are some actual runtime snapshots
Quick watch results on c on 1st call (tabbed):
- calls {Length=1} System.Object[]
- [0] {Length=3} string[]
[0] "B" string
- [1] {Length=2} string[]
[0] "C" string
[1] "D" string
[2] "E" string
Quick watch results on c on subsequent calls (tabbed):
- calls {Length=3} System.Object[]
[0] "B" string
- [1] {Length=2} string[]
[0] "C" string
[1] "D" string
[2] "E" string
The following code produces the same result:
using System;
using System.Reflection;
namespace RemoveMe
{
class Problem
{
private Object[] objPrm = new Object[]{"A",new Object[] {"B", new
Object[]{"C","D"} ,"E"}};
[STAThread]
static void Main(string[] args)
{
Problem p = new Problem();
p.Demonstrate();
}
public void Demonstrate()
{
this.Call();
this.Call();
}
public void Call()
{
Object retObj = this.GetType().InvokeMember("Total",
BindingFlags.InvokeMethod, null, this,this.objPrm);
}
public Object Total(string v, params Object[] c)
{
return null; // Breakpoint here
}
}
}
Papa.Coen wrote: The following code produces the same result
<snip>
Thanks. (I modified it to print out the contents - it's helpful not to
have to run inside a debugger to see a problem.)
I suspect it's a .NET 1.1 bug - I only see it when compiling with the
1.1 compiler.
Very odd though... my guess is that the best response you'll get if you
raise it with MS is "it's fixed in 2.0" although I could be wrong. I
don't know how best to work around it though, other than to not use
params parameters...
Jon
Using .net 2.0 and not using params is not an option for me (now)
I work around it with the following statement:
if(c[0] is string)
{
// Process
}
else
{
foreach(Object[] call in c)
{
// Process
}
}
Not very elegant, I still want to know what the problem is. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Richard |
last post by:
I have written a static method that uses the Reflection API to scrape
all of the names of the instance variables in a class and their
corresponding values; and then returns a hashMap containing a...
|
by: Derek Hart |
last post by:
I have the following code:
Me.GetType().InvokeMember(FunctionToRun, BindingFlags.InvokeMethod, Nothing, Me, params)
I can send in a string from a database into the FunctionToRun variable, and...
|
by: Gerhard Esterhuizen |
last post by:
Hi,
I am observing unexpected behaviour, in the form of a corrupted class
member access, from a simple C++ program that accesses an attribute
declared in a virtual base class via a chain of...
|
by: Sunny |
last post by:
Hi,
I have an old problem which I couldn't solve so far. Now I have found a post
in that group that gave me an idea, but I can not fully understand it.
The problem is: I'm trying to use a...
|
by: trevorelbourne |
last post by:
Hi,
I am having trouble accessing the elements of an array using
reflection. This is the code I am having trouble with:
FieldInfo Fields = Obj.GetType().GetFields();
foreach (FieldInfo fi in...
| |
by: =?Utf-8?B?UmVuYXVkIExhbmdpcw==?= |
last post by:
Hello,
I have an asp.net web page (say page.aspx) which derives from a custom base
page object (CustomPage : BasePage : System.Web.UI.Page) Which has a method
called DoSomething(params). My web...
|
by: FFMG |
last post by:
Hi,
I was looking at
http://www.php.net/manual/en/function.call-user-func-array.php and I
was wondering...
Given,
// --
function foo( &$params)
{
|
by: Just Another Victim of the Ambient Morality |
last post by:
HTMLParser is behaving in, what I find to be, strange ways and I would
like to better understand what it is doing and why.
First, it doesn't appear to translate HTML escape characters. I don't...
|
by: Giovanni Gherdovich |
last post by:
Hello,
in the following code I have a pointer (to function), say p,
of type
double (*)(double, double, void*)
and I try to fix the second argument of the function *p
to a given value (using...
|
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,...
|
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...
| |
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...
|
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,...
|
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...
|
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...
|
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...
|
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 ...
| |
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...
| |