|
-
Oct 21st, 2005, 08:07 AM
#1
Thread Starter
Hyperactive Member
Is is possible to catch such event?
Hello,
I created class which has public property with get accesor.
This property returns other class.
Example:
Object obj = Myclass.MyObjectProperty
I need to know when this object is accesed with get and when with set accesor.
obj.ObjectsPropery = "I need to know, then SET accsor is fired"
or
string objectPropertyValue = obj.ObjectsPropery; This time GET accsor is fired.
Is any way to catch this trigers?
Event must be catched in Myclass class.
-
Oct 21st, 2005, 10:02 AM
#2
Re: Is is possible to catch such event?
Sure, just define PropertyGet and PropertySet events for your class. You could use the EventHandler delegate type, or define your own.
e.g.
Code:
delegate void PropertyEventHandler (Athing Sender);
class Athing
{
public event PropertyEventHandler GetAccess;
public event PropertyEventHandler SetAccess;
private long _someValue;
public long SomeValue
{
get
{
GetAccess(this);
return _someValue;
}
set
{
_someValue = value;
SetAccess(this);
}
}
}
But you do have to raise them in each accessor method. You may also want to define seperate events for each property.
-
Oct 21st, 2005, 11:08 AM
#3
Re: Is is possible to catch such event?
oooooooooooh big problem with your code, you need to check for null values (me thinks )
so
if (GetAccess!=null) GetAccess(this);
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Oct 21st, 2005, 11:24 AM
#4
Re: Is is possible to catch such event?
My bad, yes you do need to do that, in case any inconsiderate fools don't allocate event handlers before assigning/reading property values
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|