joe_pool_is
Contributor
I'm interested in creating an event in my inherited class.
Given this:
I want to add some kind of event handler that can react whenever TestString is set.
Example1:
Now, with some event handler, data1's _type should be DbType.That.
Example 2:
Now, with some event handler, data2's _type should be DbType.Here.
The event handler would parse the text in the string using something similar to this:
I don't know how create an event handler for a variable, though.
Obviously, the class I'd use this for is a little more complicated than that. The enumeration would be a type of product, type of employee, type of business, type of process, etc.
I appreciate your help.
~Joe
Given this:
Code:
public abstract class ZBase {
string _test;
public ZBase() {
_test = string.Empty;
}
public string TestString { get { return _test; } set { _test = value; } }
}
public class MyData1 : ZBase {
public enum DbType = { None=0, This=1, That=2 };
DbType _type;
public MyData1() {
_type = DbType.None;
}
}
public class MyData2 : ZBase {
public enum DbType = { None=0, Here=1, There=2, Expired=4 };
DbType _type;
public MyData2() {
_type = DbType.None;
}
}
I want to add some kind of event handler that can react whenever TestString is set.
Example1:
Code:
MyData1 data1 = new MyData1();
data1.TestString = "I am that";
Example 2:
Code:
MyData2 data2 = new MyData2();
data2.TestString = "I am here";
The event handler would parse the text in the string using something similar to this:
Code:
// some kind of event handler:
if (-1 < TestString.IndexOf("that")) {
_type = DbType.That;
}
I don't know how create an event handler for a variable, though.
Obviously, the class I'd use this for is a little more complicated than that. The enumeration would be a type of product, type of employee, type of business, type of process, etc.
I appreciate your help.
~Joe