The Countdown Is On – Get Ready for the MVP Global Summit! – Microsoft MVP Award Program Bloghttps://t.co/AkxVeAwJSn 来週シアトル近郊でMVP Global Summitというのがあるのか。参加してみようかな。
Windows Serverは、Server Coreで提供されます。 Server Coreは、コンパクトで身軽な反面デスクトップエクスペリエンスが提供されないため手軽なサーバー管理が難しくなります。 オンプレミスの環境であれば、RSATなどを利用できますが、クラウド環境では難しい状況あります。 これらの問題を解決する新しいWebベースのサーバー管理ツール (Honolulu プロジェクト) について紹介します。
// 何か IEnumerable<TElement> なもの
IEnumerable<ToDo> toDoes = new ToDoList();
例えばこんなクラス:
class ToDoList : IEnumerable<ToDo> // サンプル コレクション
{
public IEnumerator<ToDo> GetEnumerator()
{
yield return new ToDo { Id = 1, Title = "filing tax returns", Deadline = new DateTime(2018, 12, 1) };
yield return new ToDo { Id = 2, Title = "report of a business trip", Detail = "\"ASAP\"", DaySpan = new DaySpan(3), Priority = Priority.High };
yield return new ToDo { Id = 3, Title = "expense slips", Detail = "book expenses: \"C# 6.0 and the .NET 4.6 Framework\",\"The C# Programming\"", Priority = Priority.Low, Done = true };
yield return new ToDo { Id = 4, Title = " wish list ", Detail = " \t (1) \"milk\"\n \t (2) shampoo\n \t (3) tissue ", Priority = Priority.High };
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
using System;
using System.Collections;
using System.Collections.Generic;
abstract class Figure
{
public abstract void Draw();
}
class LineFigure : Figure
{
public override void Draw() => Console.WriteLine("Line!"); // 仮実装
}
class EllipseFigure : Figure
{
public override void Draw() => Console.WriteLine("Ellipse!"); // 仮実装
}
class CadModel : IEnumerable<Figure>
{
public IEnumerator<Figure> GetEnumerator()
{
yield return new LineFigure ();
yield return new LineFigure ();
yield return new EllipseFigure();
yield return new LineFigure ();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
class CadView
{
public IEnumerable<Figure> DataSource {
set { value.ForEach(figure => figure.Draw()); }
}
}
class Program
{
static void Main()
{
new CadView().DataSource = new CadModel();
}
}
static class EnumerableExtensions
{
public static void ForEach<TElement>(this IEnumerable<TElement> @this, Action<TElement> action)
{
foreach (var element in @this)
action(element);
}
}
この記事では、C# の interface と partial class を使ったイディオムをご紹介したい。
先のコードのようにいきなりシリアライズが必要なそれぞれのクラスの中に SvgSerialize メソッドと BinarySerialize メソッドを追加するのではなく、先ず partial class とだけしてみる。
MiniCad.cs
using System;
using System.Collections;
using System.Collections.Generic;
abstract partial class Figure
{
public abstract void Draw();
}
partial class LineFigure : Figure
{
public override void Draw() => Console.WriteLine("Line!"); // 仮実装
}
partial class EllipseFigure : Figure
{
public override void Draw() => Console.WriteLine("Ellipse!"); // 仮実装
}
partial class CadModel : IEnumerable<Figure>
{
public IEnumerator<Figure> GetEnumerator()
{
yield return new LineFigure ();
yield return new LineFigure ();
yield return new EllipseFigure();
yield return new LineFigure ();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
class CadView
{
public IEnumerable<Figure> DataSource {
set { value.ForEach(figure => figure.Draw()); }
}
}
class Program
{
static void Main()
{
var model = new CadModel();
new CadView().DataSource = model;
model.SvgSerialize ();
model.BinarySerialize();
}
}
static class EnumerableExtensions
{
public static void ForEach<TElement>(this IEnumerable<TElement> @this, Action<TElement> action)
{
foreach (var element in @this)
action(element);
}
}
この Main メソッドでは、SvgSerialize メソッドを BinarySerialize メソッドを使っているが、この時点ではどこにも実装がない。