Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Invokation added at runtime?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ympostor - 23 Nov 2006 11:08 GMT
I have an abstract class with a bool property:

class Abstract {
  protected bool throwException;

  protected void ThrowException{
    if (this.throwException){
      throw new MyException();
    }
  }
}

I then have two derived classes that have propertys:

class A : Abstract {
  property X {
    get { ... }
    set { ... }
  }

  property Y {
    get { ... }
    set { ... }
  }
}

class B : Abstract {
  property Z {
    get { ... }
    set { ... }
  }
}

How can I implement an scenario where the objects from class A or from
class B invoke the abstract method ThrowException every time a property
is accessed I mean, inserting the call as the first instruction of the
get/set methods, without having to coding it, just inserting the call at
runtime (modifying the accessors at runtime)?

Thanks in advance.

--
Truong Hong Thi - 23 Nov 2006 11:30 GMT
You may checkout some AOP (Aspect Oriented Programming) containers,
like http://www.springframework.net

Thi
http://thith.blogspot.com

> I have an abstract class with a bool property:
>
[quoted text clipped - 38 lines]
>
> --
Jon Skeet [C# MVP] - 23 Nov 2006 14:31 GMT
> I have an abstract class with a bool property:

<snip>

> How can I implement an scenario where the objects from class A or from
> class B invoke the abstract method ThrowException every time a property
> is accessed I mean, inserting the call as the first instruction of the
> get/set methods, without having to coding it, just inserting the call at
> runtime (modifying the accessors at runtime)?

It sounds like you're after Aspect-Oriented Programming (AOP). I
haven't done any of that on .NET (and only a bit in Java) but you may
well find some useful articles and libraries online. I would guess that
most are likely to intercept assembly loading and weave the extra calls
in at that point.

Jon

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.