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 3598690
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:16:25+00:00 2026-05-18T20:16:25+00:00

I want to call a partial method from outside of the declaring class. This

  • 0

I want to call a partial method from outside of the declaring class. This is not allowed as partial methods are implicitly private. You can not set a delegate to point to a partial so I am proposing the following:

  public partial class MyClass  {

      AnotherClass _anotherClass;

      public MyClass  () {
         _anotherClass = new AnotherClass();
         _anotherClass.Method = new Action(() => {            
            this.Method(); 
         });
      }

      partial void Method();

      //sometimes this method will be implemented
      //partial void Method() {
         //do something
      //}
   }

   public class AnotherClass {

      public Action Method { get; set;}

      public void SomeOtherMethod(){
         this.Method();
      }
   }

The classes are tightly coupled, they are in a parent child relationship. I want the parent to have a method that it can override to know about property changes on the child. I could attach event handlers to each of the children however the child already knows about its parent so having the child inform the parent directly seems like the way to go. Except when the parent does not care which is why I want to be able to implement a partial if I do care. This question is basically about ease of programming vs performance. I know I could attach event handlers only to the situation where I do care, but with the implementation as above I can generate all the partial methods and only implement the partials if I care.

My question relates to the times that the partial method Method() is not implemented. When the Action method is called will the compiler optimise it away as its body is empty? If I get a heap of these Action calls being made could I suffer a performance penalty? Is there a better way to get the same functionality?

  • 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. Editorial Team
    Editorial Team
    2026-05-18T20:16:26+00:00Added an answer on May 18, 2026 at 8:16 pm

    Per, MSDN (emphasis added):

    One part of the class contains the
    signature of the method. An optional
    implementation may be defined in the
    same part or another part. If the
    implementation is not supplied, then
    the method and all calls to the method
    are removed at compile time.

    Thus, no real penalty as the calls are optimized away.

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

Sidebar

Related Questions

No related questions found

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.