Hi All,
There is a scenario, in which there is a counter in my base class.
There is some initial value of this counter (check below code). Now
there is a function "DecreaseCount", which will decrease count. Now I
want some functionality like when this counter become zero(0) a
delegate will be fired of derived class. This is working fine.
Now, on my UI side this instance of Tester and Developer are a
node of a TreeView. There are lots of other instance of same classes in
that TreeView. If any company having more than one(0) Employee, the
color of TreeNode should be Green. And when it becomes to Zero(0) then
color of TreeNode should become Red.
This useless to pass every time a TreeNode to Employee class. Now
I want to write a code to change the color in my UI part. And want to
call this Method/Event from by Super (base) class when the counter
becomes Zero....
The following is my effort.....
Give your feedback....
/////////// Code Start /////////////
using System;
using System.Windows.Forms;
namespace DelegateInhertanceTest
{
public delegate void NotifierCall();
public abstract class Employee
{
//public delegate void ChangeNotifier();
NotifierCall notifierCall;
int counter = 5;
//Constructor
public Employee()
{
notifierCall = new NotifierCall(this.NotifyCall);
}
public Employee(int counter)
{
this.counter = counter;
notifierCall = new NotifierCall(this.NotifyCall);
}
public abstract void NotifyCall();
public virtual void NotifyCall()
{
MessageBox.Show("Call of Delegate In Base");
}
public void DecreaseCount()
{
this.counter--;
if (this.counter == 0)
{
this.notifierCall();
}
}
}
public class Tester : Employee
{
//Default Constructor
public Tester()
{
}
public override void NotifyCall()
{
MessageBox.Show("NotifyCall of Delegate In Derived of Tester");
}
}
public class Developer : Employee
{
//Default Constructor
public Developer()
{
}
public override void NotifyCall()
{
MessageBox.Show("NotifyCall of Delegate In Derived of Developer");
}
}
public class EmployeeDemo
{
static void Main()
{
Employee testers = new Tester();
Employee developers = new Developer();
while(true)
{
testers.DecreaseCount();
}
}
public void NotifyCall()
{
MessageBox.Show("Call of induvidual instance");
}
}
}
////// Code End //////
Thanks In Advance.....
Waiting for your feedback....
Thanks & Regards,
Rushikesh
Integreon