c# - Erroneous code, when overriding async method. Can this behavior be turned off? -


let's consider class:

public class {     public virtual async task fooasync()     {         await task.delay(3000);     } } 

if you'll try override fooasync typing "override" + selecting fooasync list, vs 2013 code editor generate code:

    public override async task fooasync()     {         return base.fooasync();     } 

which, obviously, won't compile, until you'll change return await.

i know, async implementation detail, , changed in derived type, isn't cause generated code, doesn't compile initially.

can behavior turned off (e.g., using vs settings)?

i don't believe there's way change behaviour. code added comes snippet, found (on machine) under c:\program files (x86)\microsoft visual studio 12.0\vc#\snippets\1033\refactoring\methodoverridestub.snippet. snippet is:

<?xml version="1.0" encoding="utf-8"?> <codesnippets  xmlns="http://schemas.microsoft.com/visualstudio/2005/codesnippet">     <codesnippet format="1.0.0">         <header>             <title>method override stub</title>             <description>snippet overriding method</description>             <author>microsoft corporation</author>             <snippettypes>                 <snippettype>refactoring</snippettype>             </snippettypes>         </header>         <snippet>             <declarations>                 <literal editable="true">                     <id>signature</id>                     <default>signature</default>                 </literal>                 <literal>                     <id>callbase</id>                     <function>callbase(method)</function>                 </literal>             </declarations>             <code language="csharp">                 <![cdata[$signature$ {     $end$ $callbase$ }]]>             </code>         </snippet>     </codesnippet> </codesnippets> 

unfortunately, can see, actual "interesting" bits determine method signature , invoke base class method not part of snippet - they're calculated code instead.

visual studio 2015 (looking @ rc / 14.0.22823.1 d14rel) appears resolve issue, in opposite way how you've asked - avoids copying async signature, more correct since async shouldn't considered part of method signature, think allude in question; it's implementation detail , changing how method implemented shouldn't affect signature.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -