Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 01:12
    dotnet-issue-labeler[bot] labeled #57346
  • 01:12
    jmarolf opened #57346
  • 00:16
    AlekseyTs review_requested #57345
  • 00:16
    AlekseyTs review_requested #57345
  • 00:16
    AlekseyTs review_requested #57345
  • 00:16
    AlekseyTs labeled #57345
  • 00:16
    AlekseyTs opened #57345
  • Oct 23 22:57
    RikkiGibson commented #57343
  • Oct 23 22:45
    jcouv synchronize #57318
  • Oct 23 21:38
    jcouv synchronize #57318
  • Oct 23 19:45
    msftbot[bot] milestoned #57332
  • Oct 23 19:45

    RikkiGibson on main-vs-deps

    Add ServiceHub core host integr… Implement 'Enable nullable refe… Support file headers wrapped in… and 22 more (compare)

  • Oct 23 19:45
    RikkiGibson closed #57332
  • Oct 23 19:45
    RikkiGibson auto_merge_disabled #57332
  • Oct 23 19:30
    jcouv synchronize #57318
  • Oct 23 19:13
    jcouv synchronize #57318
  • Oct 23 19:08
    jcouv edited #57318
  • Oct 23 18:53
    KevRitchie commented #50259
  • Oct 23 18:17
    dotnet-issue-labeler[bot] labeled #57344
  • Oct 23 18:17
    dotnet-issue-labeler[bot] labeled #57344
Yair Halberstadt
@YairHalberstadt
Here's a simple hacky way to do it if the result is a constant. The user marks a static method as CompileTimeEvaluated using an attribute. The SG takes only that method and copies it into a new compilation which has the same metadata references as the previous compilation. It emits that compilation as an assembly and runs that method. It then puts the result in a property somewhere.
That would work reasonably well if the result is any serializable type, but deserialization is likely to be more expensive than just running the method at runtime anyway.
arturohernandez10
@arturohernandez10
@YairHalberstadt Thanks a lot!! I am really going after extracting patterns from codebases. I would like to have a Pattern project, similar to Test project. Just like you can do a Partial evaluation you could take an existing piece of code. Give it a generic interface and using generic types you could define the pattern with a lower abstraction cost. ;)
Yair Halberstadt
@YairHalberstadt
I'm not sure i understood to be honest
arturohernandez10
@arturohernandez10

@YairHalberstadt
Yes, here is an example:

    public static TOut Pattern<TIn,TOut>(Attributes attributes) => (TIn input) =>
    {
        var result = new TOut();

        foreach (var attribute in attributes)
            if (attribute.IsEnum())
                attribute.Assign(result, input);

        return result;
    }

    public static Person Example(Student person)
    {
        var result = new Person();

        result.Degree = __.GivenField(person.Degree.ToString(), a.IsEnum());

        return result;
    }

In sample we can use an example object (not to write generic). __.GivenField Is just a type preserving function, which also has room for an expression tree. The expression tree is used to determine the kind of code generation to be used. And would match the pattern above. The idea is that the pattern implementation code, will always be harder to read. While the example code should be much easier. I think this could be a good thing to try.

I would like to generate the patterns from example decorated code. And that could be a second step. I like the idea of writing a quick first implementation even if the code is ugly.
Авдеев Вячеслав
@lsoft
so, with vs2022 preview4 incremental generators are going in the wild))) but no docs and examples exists :( (except for single not completed md file)...
arturohernandez10
@arturohernandez10
@lsoft do you have a link to that single md file?
2 replies
Leandro T. C. Melo
@ltcmelo
hi everyone, I'd like to share that we've made public a GH repo with our Roslyn-based syntax rewriter tool for C#
I don't think that it's useful for Roslyn itself, but it may be useful to people creating Roslyn-based tools
I appreciate if you chould re-share with anyone you believe might be interested :-)
thanks!
CyrusNajmabadi
@CyrusNajmabadi
ooh, this looks cool
i will ahve to look at those tests to see what htey all do :)
Leandro T. C. Melo
@ltcmelo
don't look too close :-P
joking... feedback/critique from you would be highly appreaciated @CyrusNajmabadi
some rewriters are better tested than others
and their "coverage" is pretty much driven by the diversity of code we've encountered in the field (at this point, we've accumulated a number of POCs and customers)
e.g., you won't see proper handling of co/contravariance in generics, as we don't bump into them with frequency
and, I only have so much time and need to prioritize :-)
Bernd Baumanns
@bernd5
thanks for sharing
Bernd Baumanns
@bernd5
I tried once to write a linq-rewriter, too.
I tried your code - and it fails at the same point
Bernd Baumanns
@bernd5
the problem is the shadowing of thing
it would be great if that would work, too.
BTW.: this is the most complex linq query I have ever seen...
Bernd Baumanns
@bernd5
If you translate it you get: System.ArgumentException: "An item with the same key has already been added. Key: ____TRANSPARENT2"
Bernd Baumanns
@bernd5
I took the wrong sample
but both fail
arturohernandez10
@arturohernandez10
@ltcmelo Awesome!!!
still, feel free to create an GH issue if you'd like
thanks @arturohernandez10
Atul Sharma
@atksharma_twitter
Folks - For some reason , After updating to the latest version of roslyn dependencies, the documents are not loading inside the solution after opening the workspace .. Any body else facing this issue ?

Folks - For some reason , After updating to the latest version of roslyn dependencies, the documents are not loading inside the solution after opening the workspace .. Any body else facing this issue ?

These are the version of nugets we are currently using - -Microsoft.Build.Locator 1.4.1
Microsoft.CodeAnalysis.Analyzers 3.3.2
Microsoft.CodeAnalysis.CSharp 3.11.0
Microsoft.CodeAnalysis.CSharp.Workspaces 3.11.0
Microsoft.CodeAnalysis.Workspaces.MSBuild 3.11.0

Hugh Gleaves
@Korporal
VS has always been limited when it comes to being able to rename namespaces, I wonder if VS 2022 will offer improvements in this area...
2 replies
CyrusNajmabadi
@CyrusNajmabadi
can you give an example of what you mean?
Hugh Gleaves
@Korporal
Yes, if I have a new project and I just dream up a temp name like 'HolidayAPI' intending to refine that later, well later, I'd like to open one of the source files and click the namespace name "HolidayAPI" and rename it to say "Nep.Scheduling" but it never lets you, it hates you trying to introduce new periods into the name.
1 reply
I'm sure there are reasons but I wonder if there's scope for revisiting this.
CyrusNajmabadi
@CyrusNajmabadi
you can definitely file suggestion on this.
Hugh Gleaves
@Korporal
alright, I'll do that later, thanks Cyrus.
timiil
@timiil
hi,hi , i am trying do a task:
walk through a Lambda, get all MemberAccessSyntax
ExpressionSyntax es = SyntaxFactory.ParseExpression(expr); //expr is a string
any simple way to walkthough the 'es' that get all MemberAccessExpressionSyntax inside it ? we know that the a great deal of kind XXXXSyntax inside the tree...
Martin Vseticka
@MartyIX

Guys, I'm working on an analyzer which bans some APIs. So it basically goes through syntaxTree.GetRoot().DescendantNodes().OfType<IdentifierNameSyntax>() and checks INamespaceSymbol namespaceSymbol = semanticModel.GetSymbolInfo(node).Symbol?.ContainingNamespace;.

The function that does this is public IEnumerable<(IdentifierNameSyntax, INamespaceSymbol )> FindForbiddenIdentifiers(SemanticModel semanticModel). My implementation of the method does "yield return (node, @namespace);" so that FindForbiddenIdentifiers returns as soon as possible and a diagnostic can be reported to a Visual Studio user. My colleague would prefer FindForbiddenIdentifiers to return a list (as it is computed faster 240ms as opposed to 300ms with yield return- the intervals are taken from unit tests). Is there some recommendation what is better? I would expect that yield return should be used by default as I understand I don't really need an allocation for the returning list but still my implementation is "slower" in total.