Results 1 to 4 of 4

Thread: Is is possible to catch such event?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2000
    Location
    Europe, Lithuania
    Posts
    309

    Exclamation 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.

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  3. #3
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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!!

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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
  •  



Click Here to Expand Forum to Full Width