Thanks to both of you for your reply. Im starting to see that this is probably not something c# is encouraging you to do.
I got a solution working, but its very nasty and I was wondering if someone could help me make the syntax a bit better?
It has to follow this rules:
Must be safe code.
Must allow me to change the value of the item passed in in its original place.
Must work with properties.
Code:
public delegate void SetFunctor(object obj);
public delegate object GetFunctor();
class DebugItem
{
SetFunctor m_set;
GetFunctor m_get;
string m_text;
DebugItemValueType m_type;
public DebugItem( SetFunctor setter, GetFunctor getter, string text, DebugItemValueType type)
{
m_set = setter;
m_get = getter;
m_text = text;
m_type = type;
}
public void Update(int value)
{
switch (m_type)
{
case DebugItemValueType.E_bool:
if (value == -1)
m_set(false);
else if (value == 1)
m_set(true);
break;
}
}
}
And here is how I create a instance:
Code:
DebugItem test = new DebugItem( delegate(Object boolVal) { Active = (bool)boolVal; },
delegate() { return Active; },
"some string",
DebugItemValueType.E_bool);
Any ideas?