Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Aug 01 22:07
    User @CyrusNajmabadi unbanned @VBAndCs
  • May 13 18:16
    @CyrusNajmabadi banned @Korporal
  • Jan 29 18:46
    @CyrusNajmabadi banned @VBAndCs
  • Jan 16 2021 19:06
    @CyrusNajmabadi banned @JuliusRFriedman_twitter
  • Nov 01 2020 06:15
    @CyrusNajmabadi banned @juliusfriedman
  • Jan 31 2019 21:39

    gafter on master

    Propose Feb 11 agenda (#2187) (compare)

  • Jan 31 2019 21:39
    gafter closed #2187
  • Jan 31 2019 19:42
    gafter edited #2115
  • Jan 31 2019 15:46
    jcouv edited #1565
  • Jan 31 2019 14:51
    yigitgursoy closed #1958
  • Jan 31 2019 13:43
    ichensky closed #2190
  • Jan 31 2019 12:17
    ichensky opened #2190
  • Jan 31 2019 04:38
    MarkPflug edited #2189
  • Jan 31 2019 04:37
    MarkPflug edited #2189
  • Jan 31 2019 04:37
    MarkPflug edited #2189
  • Jan 31 2019 04:36
    MarkPflug opened #2189
  • Jan 30 2019 23:15
    MohammadHamdyGhanem opened #2188
  • Jan 30 2019 20:01
    gafter review_requested #2187
  • Jan 30 2019 20:01
    gafter review_requested #2187
  • Jan 30 2019 20:01
    gafter review_requested #2187
CyrusNajmabadi
@CyrusNajmabadi
In this case it would likely be a request about inference working in ?? (Though I haven't investigated to see if that's what is the issue here)
Antony Male
@canton7

After enabling nullables, I think the single most irritating issue it causes is all the gratuitous !s I have to stick on the end of ToString calls to shut the compiler up. Whose brillant idea was it to specify that as returning string? :interrobang:

@masonwheeler https://stackoverflow.com/a/69944733/1086121

So unless you're calling object.ToString(), or calling ToString on a generic type, the signature almost certainly returns a non-nullable string. When you override ToString, the VS-generated code returns string
masonwheeler
@masonwheeler
...so why exactly is a variable declared inside a do ... while block considered "not in scope" in the while clause?
Antony Male
@canton7
I suspect simply, because traditionally the { and } introduce a new scope.
CyrusNajmabadi
@CyrusNajmabadi
Primarily because that's kinda how blocks work. I can't think of any case where sometime defined in a block leak into an outer scope.
David Arno
@DavidArno
Not sure if anyone uses this these days but just in case, I’m trying to communicate with @CyrusNajmabadi but he seems determined to censor every post I make and won’t explain his actions. Hoping I can engage him here in a private chat to try and get to the bottom of things.
Bernd Baumanns
@bernd5
you can try on discord
David Arno
@DavidArno
@bernd5 thanks I didn’t realise discord supported private messages. I’ve tried there too. Cheers.
CyrusNajmabadi
@CyrusNajmabadi
Since it was brought up here. The posts were hidden for being off topic. Posts on GitHub.com/dotnet/csharplang have to be on the discussion topic they are on.
David Arno
@DavidArno
Yes, you already said that in the discussion itself. It's a great shame that MS have allowed someone like yourself to be a moderator of such an important forum. But they have, and I just have to "suck it up" as there's nothing I can do about that.
CyrusNajmabadi
@CyrusNajmabadi
@DavidArno I cannot respond on discord as you have left the server.
It's a great shame that MS have allowed someone like yourself to be a moderator of such an important forum.
Everyone in the dotnet org can moderate dotnet communities.
As mentioned in the thread and offline, we ask that people keep their posts on topic. Continued off topic posts will be marked as such.
and I just have to "suck it up" as there's nothing I can do about that.
Correct. You need to follow the rules of these communities if you wish to continue being allowed to participate in them.
CyrusNajmabadi
@CyrusNajmabadi
If you're not ok with the literal project owners and repo maintainers moderating their own forums, I'm not sure what to tell you.
CodeChops
@Code-Chops
Hello. At the moment I am using GenericMath (which is in preview).Does anyone know how I can cast INumber<TPrimitive> to an primitive integral type in C# without much overhead? I need this in order to access indices of arrays, lists, etc.
CyrusNajmabadi
@CyrusNajmabadi
you should be able to do INumber<...> n = ... then int x = (int)n;
masonwheeler
@masonwheeler
Dictionary<TKey, TValue>.TryGetValue defines its out param as [MaybeNullWhen(false)] out TValue value. So why does the compiler consider it nullable in the following code?
var c = dict.TryGetValue(name, out var value);
DoSomething(name, c); //no shenanigans here such as passing c by ref
if (c)
{
   DoSomethingElse(value); //compiler believes value might be null
}
HaloFour
@HaloFour
Because the flow analysis doesn't track the value when you assign it to a variable
masonwheeler
@masonwheeler
*blink blink* Then what's the point of having it at all?
HaloFour
@HaloFour
It works when the TryGetValue is in the if statement
CyrusNajmabadi
@CyrusNajmabadi
@masonwheeler if you want that scenario to work, please open a discussion at Roslyn.
Currently the compiler doesn't track the relation between variables. But if you can come up with a good specification for that (and/or are willing to provide a good impl) I think it has a high chance of being taken.
HaloFour
@HaloFour
I think there might be an open discussion about it
CyrusNajmabadi
@CyrusNajmabadi
regardless, this channel is not tracked. Best to use github or discord for these questions/discussions. thanks!
Kristoffer Silva Lagerström
@kslagerstrom
Hi there,
Think on it:
switch(x)
{
case 100, 101, 102:
break;
}
and in the last iteraction, without break statement
CyrusNajmabadi
@CyrusNajmabadi
Already supported
case 100 or 101 or 102:
Or:
case >= 100 and <= 102:
@kslagerstrom
Victor Irzak
@virzak

Hi all,

If you have a need for sync and async implementation of the same routine, you can now use a source generator, which will generate a sync method from async.

Check it out at
https://github.com/zompinc/sync-method-generator

[Zomp.SyncMethodGenerator.CreateSyncVersion]
static async Task WriteAsync(ReadOnlyMemory<byte> buffer, Stream stream, 
CancellationToken ct)
    => await stream.WriteAsync(buffer, ct).ConfigureAwait(true);

will generate:

static void Write(ReadOnlySpan<byte> buffer, Stream stream)
    => stream.Write(buffer);
vladd
@vladd

If you have a need for sync and async implementation of the same routine, you can now use a source generator, which will generate a sync method from async.

I wonder how it's going to deal with TaskCompletionSource.

Andrew Arnott
@AArnott
How can a C# source generator know when it's safe to emit static abstract members of interfaces? The conditions would be langversion >=11 (which is easy to check) and targeting .NET 7+. But how do I test for the target framework?
Andrew Arnott
@AArnott
How do I provide an EqualityComparer in a group by linq expression? I need to appease RS1024 by providing a SymbolEqualityComparer in this:
var reportSites = from info in callerToCalleeMap[implicitUserMethod]
                  where transitiveClosureOfMainThreadRequiringMethods.Contains(info.MethodSymbol)
                  group info by info.MethodSymbol into bySymbol
                  select new { Location = bySymbol.First().InvocationSyntax.GetLocation(), CalleeMethod = bySymbol.Key };
2 replies
Youssef Victor
@Youssef1313

How can a C# source generator know when it's safe to emit static abstract members of interfaces? The conditions would be langversion >=11 (which is easy to check) and targeting .NET 7+. But how do I test for the target framework?

@AArnott You could get VirtualStaticsInInterfaces from System.Runtime.CompilerServices.RuntimeFeature and check whether it has System.Runtime.Versioning.RequiresPreviewFeaturesAttribute

Youssef Victor
@Youssef1313
It would be something similar to the following (I'm writing directly here so code may not be directly copy/paste-able)
private static bool IsSupported(Compilation compilation)
{
    var runtimeFeatureSymbol = compilation.GetTypeByMetadataName("System.Runtime.CompilerServices.RuntimeFeature");
    var virtualStaticsInInterfaces = runtimeFeatureSymbol?.GetMembers("VirtualStaticsInInterfaces");
    if (virtualStaticsInInterfaces.IsDefaultOrEmpty)
    {
        return false;
    }

    var previewFeaturesAttributeSymbol = compilation.GetTypeByMetadataName("System.Runtime.Versioning.RequiresPreviewFeaturesAttribute");
    if (previewFeaturesAttributeSymbol is null)
    {
        return false;
    }

    return !virualStaticsInInterfaces[0].GetAttributes().Any(attr => previewFeaturesAttributeSymbol.Equals(attr.AttributeClass, SymbolEqualityComparer.Default))
}
Andrew Arnott
@AArnott
Thank you @Youssef1313. That worked great.