Giter VIP home page Giter VIP logo

Comments (3)

atifaziz avatar atifaziz commented on August 11, 2024 1

when there is an "async" before the main function.

How do you find Main in the code? What if there's a trial version of some Main that's commented out (or conditionally compiled out) and using a quick & dirty trick like regular expressions to sniff out the async before Main picks on the wrong thing?

The first thing is "can do", then "do it pretty"!

True but often when you have it working one way then there's a lesser urge to make it pretty. :)

from linqpadless.

atifaziz avatar atifaziz commented on August 11, 2024 1

Seems the code to do so is trivial with Roslyn:

var tests =
    from source in new[]
    {
        @"
        /*
        async Task Main() {
            await Task.Delay(TimeSpan.FromSeconds(1));
            Console.WriteLine(DateTime.Now);
        }
        */
        async void Foo() {}
        void Main() {}
        ",
        
        @"
        async void Foo() {}
        async void Main() {
            await Task.Delay(TimeSpan.FromSeconds(1));
            Console.WriteLine(DateTime.Now);
        }
        "
    }
    select
        CSharpSyntaxTree.ParseText(source).GetRoot()
            .DescendantNodes().OfType<MethodDeclarationSyntax>()
            .Any(md => "Main" == (string) md.Identifier.Text
                       && md.Modifiers.Any(m => m.IsKind(SyntaxKind.AsyncKeyword)));

foreach (var test in tests)
    Console.WriteLine(test);

from linqpadless.

shamork avatar shamork commented on August 11, 2024

IMO, it's ok that simply add an "await" when there is an "async" before the main function.
The first thing is "can do", then "do it pretty"!

from linqpadless.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.