PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, May 18, 2022

[FIXED] what happens if I don't implement a partial method?

 May 18, 2022     c#, partial     No comments   

Issue

I generated some code using SQLMetal and worked with it for some time. Just now, I looked through the generated code, and fond in each class a few partial functions, that I never implemented, nor were they implemented by SQLMetal. These functions were called in the code. I wonder - whats happening when I call a function like that - that doesn't exist?


Solution

These functions were called in the code. I wonder - whats happening when I call a function like that - that doesn't exist?

The call is completely removed by the compiler. Any expressions which are evaluated in order to call the method are removed too - so if you have this:

SomePartialMethod(ComputeSomeValue());

and SomePartialMethod isn't implemented, ComputeSomeValue won't be called.

Or as MSDN puts it:

If the method is not implemented, then the compiler removes the method signature and all calls to the method. The calls to the method, including any results that would occur from evaluation of arguments in the calls, have no effect at run time. Therefore, any code in the partial class can freely use a partial method, even if the implementation is not supplied. No compile-time or run-time errors will result if the method is called but not implemented.



Answered By - Jon Skeet
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,214,366

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing