序列化为C#脚本

时间:2016-10-27 22:06:58

标签: c# code-generation roslyn

Roslyn脚本允许评估仅包含对象创建表达式的C#脚本,有效地允许从脚本反序列化对象:

var script = "new Point { X = 1, Y = 2 }";
var point = await CSharpScript.EvaluateAsync<T>(script);

是否有允许进行反向序列化的库?

script = ???.Serialize(point);

1 个答案:

答案 0 :(得分:1)

由于似乎没有可以实现此目的的现有库,我编写了一个应该处理简单案例的库:https://github.com/AndriySvyryd/CSharpScriptSerializer

var input = new Point {X = 1, Y = 1};
var script = CSScriptSerializer.Serialize(input);
var output = CSScriptSerializer.Deserialize<Point>(script);