Hi folks
I have a Generic Value Type and I want to detect when the internal value
changes.
///////////////////////////////
public delegate void ValueTypeValida tionHandler<T>( T oldValue, T newValue);
public struct TestType<T>
{
private T value;
public event ValueTypeValida tionHandler<T> valueChanged;
public ValueType(T value)
{
this.value = value;
valueChanged = null;
}
public T Value
{
get { return value; }
set
{
if(valueChanged != null)
valueChanged(th is.value, value);
this.value = value;
}
}
}
//////////////////////
I want to be able to add TestType<> fields to a containing class and have
the containing class assign a delegate to each of the TestType<> fields
without naming them specifically, in the constructor of the containing
class.
So far I have got this far but I want to know how to attach the delegates to
the events.
/////////////////////////
public ContainingType( )
{
FieldInfo[] fia = GetType().GetFi elds(BindingFla gs.Instance |
BindingFlags.No nPublic);
foreach(FieldIn fo fi in fia)
{
Type ft = fi.FieldType;
object fObj = fi.GetValue(thi s);
// the next line doesn't compile; how do I pass the type of each field into
the
generic parameters ?
((TestType<ft>) fObj).valueChan ged += new
ValueTypeValida tionHandler<ft> (HandleValueCha nged<ft>);
}
////////////////////////////
TIA
Joanna
--
Joanna Carter
Consultant Software Engineer