c# - Why Conditional attribute methods aren't allowed to return other than void -


i've started learn c# book , read conditional attribute , #if compiler directive.

i know usage of #if compiler directive:

#if debug public void foo(int value) { ... } #endif 

and of conditional attribute:

[system.diagnostics.conditional("debug")] public void foo(int value) { ... } 

i know code encased #if ... #endif statements doesn't reach il conditional attribute code , calls function ommited.

my question:
why there restriction conditional attribute usage functions marked attribute have return void written here in documentation?

you compilation error in visual studio if apply attribute method not return void.

i searched information found no explanation.

the compiler not allow because semantics of code undefined or @ best rather hard understand:

[system.diagnostics.conditional("debug")] public int foo() { ... }  var x = someothermethod(foo()); 

the [conditional("debug")] attribute on method means calls method omitted compiled code if "debug" symbol present.

but if call foo() disappears compiled code, pass someothermethod()? or if call removed, assign x? how guarantee local x has value, cause compile error?

the .net team decided not go way, instead added compile-time constraint [conditional()] methods must void methods.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -