Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 63131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T18:35:04+00:00 2026-05-10T18:35:04+00:00

I know that it is possible (in theory) to create a new type at

  • 0

I know that it is possible (in theory) to create a new type at run-time, but is it possible to modify a method body of an existing type at run-time? My plan (if I can get this to work) is to tag up methods with a custom attribute, and then at run-time search for methods with the attribute, and insert some of my own code into the method body.

Any suggestions?

I suppose if I can’t get that approach to work, I could always go with a virtual method in a base class (with the attributes), combined with a static factory to spit out a derived dynamic type with my run-time generated method in the child class. This would not be quite as clean to use though.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T18:35:05+00:00Added an answer on May 10, 2026 at 6:35 pm

    PostSharp which is an aftercompiler, does something similar to what you describe, using attributes to mark injection points in the code, only difference is that it does it at compile time.

    But you can also do it at runtime not by changing method bodies but by using classes derived from ContextBoundObject which is a .Net class that lets you intercept all the calls made against it. Here is a MSDN Magazine article describing how to do AOP using ContextBoundObject. (Check the aspects in .Net part of the article)

    And as a third option you can use dynamic code generation (Reflection.Emit or CodeDom) in combination with attributes and virtual methods to dynamically generate derived classes where you can insert your code, but this is the most painful way to do it.

    Edit:

    There’s a forth option to use .Net unmanaged profiling API to intercept method JIT-ing and replace method bodies ahead of JIT-ing. This technique is sucessfully used by JustMock (Telerik) in order to mock, static methods, non virtual methods and even sealed classes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 65k
  • Answers 65k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer yes, you can assign sys.stdout to whatever you want. Create… May 11, 2026 at 11:09 am
  • added an answer You could use a BackgroundWorker and then change the UI… May 11, 2026 at 11:09 am
  • added an answer you could create a GUID and save the image as… May 11, 2026 at 11:09 am

Related Questions

I know that it is possible (in theory) to create a new type at
Is it possible to create a toggle button in C# WinForms? I know that
I know that it's possible to replace the browse button, which is generated in
I know that it is possible to check how much physical RAM is installed
Is it possible to close an InfoPath form programmatically? I know that it can
I know that JTable can sort by a single column. But is it possible
I know it is commonly used as a lock object, but is that really
A programmer I know has a website that is fully Standards Compliant. It uses
I know that it does in PHP, and I'm pretty sure it does in
I know that it does consider ' ' as NULL , but that doesn't

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.