problem with property update...

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace test
{
public delegate void D();
public interface IA
{
event D Event;
}

public
struct A : IA
{
public int i;

public event D Event
{
add
{
//assign value here
i = 123;
}
remove
{
}
}
}

public class C<T> where T: IA, new()
{
public C()
{
T t =
new T();
t.Event +=
new D(Raise);
Debug.Assert(((A)(IA)t).i == 123);
}
void Raise()
{
}
}

class Program
{

[
STAThread]
static void Main(string[] args)
{
C<A> c = new C<A>();
}
}
}

/*

Assert condition in this code is false. t.i = 0. This means that add method of event D works with a copy of t. Is it bug

I use .net framework v2.0.50727

*/



Answer this question

problem with property update...

  • Paulius

    Serjic,
    I suspect that struct A is being boxed when internally casted to IA, which would explain the behaviour.

    Changing "public struct A" to "public class A" solves the problem, as does making class C non generic.

    HTH
    --mc


  • problem with property update...