19. record
19
public record RStaff(int Id, string Name);
public record RStaff2
{
public int Id { get; init; }
public string Name { get; init; } = "";
}
public record RStaff3
{
public int Id { get; private set; }
public string Name { get; private set; } = "";
public RStaff3(int id, string name) => (Id, Name) = (id, name);
}
recordサンプル.cs | GitHub
48. HelloSourceGeneratorSample の Main() を書き換え
48
using System;
namespace HelloSourceGeneratorSample
{
class Program
{
static void Main(string[] args)
{
SourceTreeGenerated.SourceTree.Show();
}
}
partial class PartialClass
{
private partial string GetMessage();
// not implemented here.
public void ShowMessage()
=> Console.WriteLine(GetMessage());
}
}
49. 実行結果
49
This is generated code!
The following syntax trees existed in the compilation that
created this program:
- Program.cs
- .NETCoreApp,Version=v5.0.AssemblyAttributes.cs
- HelloSourceGeneratorSample.AssemblyInfo.cs
51. HelloSourceGeneratorSample の Main() を書き換え
51
using System;
using AutoNotify;
namespace HelloSourceGeneratorSample
{
class Program {
static void Main(string[] args)
{
Point point = new();
point.PropertyChanged += (point, _) => {
var p = point as Point;
Console.WriteLine($"The point has
changed: {p?.X}");
};
point.X = 100;
point.X = 200;
}
}
partial class PartialClass
{
private partial string GetMessage();
// not implemented here.
public void ShowMessage()
=> Console.WriteLine(GetMessage());
}
partial class Point
{
[AutoNotify]
private int _x;
}
}