Volta 探検 (2)

思った以上に NotSupported 扱いの型/メンバが多いかも.
id:siokoshou:20071126#c1196036439 であったらいいなぁと書いたブラウザ上で動く C# コンパイラは無理にしても,せめてExpression Trees のデモぐらいなら作れるかと思って試してみましたが,NotSupported ばっかりで全然ダメそうでした*1
現時点の Volta ですが,プリミティブな型を使った純粋なアルゴリズムで鋭意工夫という感じになりそうです.文字列処理とか数列計算,3D 計算なんかはまあ題材としては無難と.あとはまあ Web ならではの非同期対応をスパイスに味付けですか.
どう書く?org にあるようなお題 であればそれほど不自由を感じさせないかもしれませんね.
とりあえず FizzBuzz でも.

using System.Linq;
using Microsoft.LiveLabs.Volta.Html;

namespace FizzBuzzVolta
{
    public partial class VoltaPage1 : Page
    {
        public VoltaPage1()
        {
            InitializeComponent();

            var button = new Button() { InnerText = "FizzBuzz!" };
            var input = new Input() { Value = "100" };

            var para = new Paragraph()
            {
                button,
                new Span(){ InnerText = "upto: "},
                input,
            };

            button.Click += () =>
            {
                int upto = 0;
                if( !int.TryParse(input.Value, out upto) ) return;

                var table = new Table()
                {
                    new TableBody
                    (                        
                        from x in Enumerable.Range(1, upto)
                        let a = x % 3 == 0 ? "Fizz" : ""
                        let b = x % 5 == 0 ? "Buzz" : ""
                        let c = (x % 3 != 0 && x % 5 != 0) ? x.ToString() : ""
                        select new TableRow()
                        {
                            new TableCell() { InnerText = x.ToString() },
                            new TableCell() { InnerText = a + b + c }
                        } as HtmlElement
                    )
                };

                this.Document.Body.Add(table);
            };

            this.Document.Body.Add(para);
        }
    }
}

なにげに どう書く?orgC# + Volta のコードで投稿しまくるってのはありなのかも.

*1:実はJavaScript 変換が無理っぽい部分だけサーバサイドで動かせばなんとかなる? セキュリティについてはとりあえず忘れることにして