DataTable
データの文字列表現を受け入れてStringTemplate
返すメソッドを実装しようとしています。
これを行う方法はこちらとこちらで見つかりましたが、うまくいきません。
コード例:
// Here can be any table with any number of columns.
var table = new DataTable();
table.Columns.Add("StrCol", typeof(string));
table.Columns.Add("IntCol", typeof(int));
table.Rows.Add(new object[] { "Row1String", 1 });
table.Rows.Add(new object[] { "Row2String", 2 });
var data = from dataRow in table.AsEnumerable()
select dataRow;
var st = new StringTemplate("$items:{$it.StrCol$ $it.IntCol$}$");
st.SetAttribute("items", data);
Console.Write(st.ToString());
結果:
Class DataRow has no such attribute: StrCol in template context [anonymous anonymous]
Class DataRow has no such attribute: IntCol in template context [anonymous anonymous]
Class DataRow has no such attribute: StrCol in template context [anonymous anonymous]
Class DataRow has no such attribute: IntCol in template context [anonymous anonymous]
更新:
Antlr3.StringTemplate.dllバージョン3.1.0を使用する必要がありStringTemplate
ます。別のバージョンを試すことにし、 Antlr3.StringTemplate.dllバージョン3.3.0をダウンロードしました。すべて正常に動作します。DataTable
では、古いライブラリを使用してテンプレートを適用する方法はありますか?