ufcpp-live / UfcppLiveAgenda

@ufcpp live streaming agenda
MIT License
24 stars 2 forks source link

Visual Studio 17.3p2, .NET 7 Preview 5 #58

Closed ufcpp closed 1 year ago

ufcpp commented 2 years ago

配信URL: https://www.youtube.com/watch?v=p4gF3xhSPLg

https://docs.microsoft.com/en-US/visualstudio/releases/2022/release-notes-preview#17.3.0-pre.2.0 https://devblogs.microsoft.com/dotnet/announcing-dotnet-7-preview-5/

いくつかピックアップ。

Visual Sudio

ランタイム

C# 11、結構更新あり

https://gist.github.com/ufcpp/cbf99693e9e61f07bdc8b209ee2002ac https://github.com/ufcpp/UfcppSample/compare/57b2c90...46be59f

ufcpp-live commented 2 years ago
var s1 = "abc {  }";
var s2 = $"abc {{  }}"; // これを自動で convert to raw string するのは手間なはず
var s3 = $$"""abc {  }""";
ufcpp-live commented 2 years ago

ちゃんと " がいっぱいwww

image

ufcpp-live commented 2 years ago

u8 まだダメだった。

image

ufcpp-live commented 2 years ago

u8 消して、エラーガン無視したままリファクタリングかけるライフハック

image

ufcpp-live commented 2 years ago

1文字違いです!

image

ufcpp-live commented 2 years ago

1文字転地、アルファベットなら行けた

image

non-ascii ダメ?

image

ufcpp-live commented 2 years ago
// いける(隣接転置)
acb();
bac();

// ダメ
cab();

void abc() { }
ufcpp-live commented 2 years ago

image

ufcpp-live commented 2 years ago

image

ufcpp-live commented 2 years ago
enum A : byte { }
enum B : nint { }
enum C : char { } // これもダメだし、nint だけの仲間外れじゃないからセーフ。
ufcpp-live commented 2 years ago

primitive とはいったい…

using System;

const decimal d = 10.0m; // OK

Console.WriteLine(d);

static void m(Decimal d = 1.1m){} // これも OK

[A(1.1m)] // これだけダメww
class A
{
    public const Decimal X = 1.1m; // OK
}

class AAttribute : Attribute
{
    public AAttribute(Decimal d) {}
}
ufcpp-live commented 2 years ago
required x = null; // 行けた
var y = new required(); // 行けた

public class @required { } // 素の class required はダメ。 @ がすべてを解決する。

public class B
{
    public required R1 { get; set; } // ダメwww
    public required required R2 { get; set; } // 行けたww
}
ufcpp-live commented 2 years ago
    public @required R1 { get; set; } // @ はすべてを解決する
ufcpp-live commented 2 years ago

???

1テンポ遅れてエラー出たw

image

ufcpp-live commented 2 years ago
//var a0 = new A(); // これはエラー

// 余裕で無視。リフレクション強い。
var a = Activator.CreateInstance<A>();

Console.WriteLine(a);

record struct A
{
    public required string X { get; init; }
    public required int Y { get; init; }
}
ufcpp-live commented 2 years ago

image

ufcpp-live commented 2 years ago
var a0 = new A();

record struct A
{
    public required string X { get; init; }
    public required int Y { get; init; }

    public A() { } // これだとまだダメ。
    // A() が X, Y を初期化している保証がない。
}
ufcpp-live commented 2 years ago
using System.Diagnostics.CodeAnalysis;

var a0 = new A();
var a1 = new A("", 1); // これ、ダメ。(属性つけろ)

record struct A
{
    public required string X { get; init; }
    public required int Y { get; init; }

    [SetsRequiredMembers] // これで行けるようになってしまう。
    public A()
    {
        X = "";
        // 本来はここで X, Y を初期化すべき。
        // X は NRT 解析の対象なので警告出るけど、
        // Y は嘘つき放題。
    }

    public A(string x, int y)
    {
        X = x;
        Y = y;
    }
}
ufcpp-live commented 2 years ago

required メンバーの後からの追加は破壊的変更。

var a0 = new A // Z を足したら破壊的変更。エラー。
{
    X = "",
    Y = 1,
};

record struct A
{
    public required string X { get; init; }
    public required int Y { get; init; }

    public required bool Z { get; init; } // 後から追加!
}
ufcpp-live commented 2 years ago
record A
{
    public required string X { get; init; }
    public required int Y { get; init; }
}

record B : A
{
    public required bool Z { get; init; } // 派生クラスごと足せば足せるけども…
}
ufcpp-live commented 2 years ago
record A
{
    // nullable required も行けるよ
    public required string? X { get; init; }
    public required int Y { get; init; }
}
ufcpp-live commented 2 years ago
record A
{
    // nullable required も行けるよ
    public required string? X { get; init; }
    public required int Y { get; init; }

    // required 追加、ソースコード互換は壊すけど、バイナリ互換は壊さないかも。
    // 後で検証してみます。
    public required int Z { get; init; }
}
ufcpp-live commented 2 years ago

net6.0 でコンパイルして、dll にして、Reference dll

public record A
{
    public required string X { get; init; }
    public required int Y { get; init; }
}

namespace System.Diagnostics.CodeAnalysis
{
    internal class SetsRequiredMembersAttribute : Attribute { }
}
namespace System.Runtime.CompilerServices
{
    internal class RequiredMemberAttribute : Attribute
    {
        public RequiredMemberAttribute() { }
        public RequiredMemberAttribute(string name) { }
        public RequiredMemberAttribute(params string[] membernames) { }
    }
    internal class CompilerFeatureRequiredAttribute : Attribute
    {
        public CompilerFeatureRequiredAttribute(string featureName) { }
    }
}
ufcpp-live commented 2 years ago
using static iostream;

// 虚偽報告
// インライン C++ に見せかけてるだけの邪悪な C# コード。

//lang=c++
await (cout << "Hello World!" << endl);

cpp(cout << "Hello World!" << endl);

public static class @iostream
{
    public static void cpp(ConsoleOut _) { }

    public static readonly ConsoleOut cout = new();
    public static readonly ConsoleEndLine endl = new();

    public struct ConsoleOut
    {
        public static ConsoleOut operator <<(ConsoleOut x, string value) { Console.Write(value); return x; }
        public static ConsoleOut operator <<(ConsoleOut x, ConsoleEndLine _) { Console.WriteLine(); return x; }
        public override string ToString() => "";
        public System.Runtime.CompilerServices.ValueTaskAwaiter GetAwaiter() => default;
    }

    public struct ConsoleEndLine
    {
        public override string ToString() => "";
    }
}
ufcpp-live commented 2 years ago
using std = X;

// std::cout を通すためには cout が型名でないとダメ。
std::cout x;

// cout が型名だと << が通らない…
_ = std::cout << "";

namespace X
{
    public class cout { }
}