我想序列化枚举类型,以便它返回一个数组,其中枚举作为一个对象,包含"值","名称"和数据注释值.我需要序列化方面的帮助.这是我到目前为止所做的:枚举:
public enum Status
{
[Display(Name="Active status")]
Active = 1,
[Display(Name = "Deactive status")]
Deactive = 2,
[Display(Name = "Pending status")]
Pending = 3
}
Run Code Online (Sandbox Code Playgroud)
应序列化的DTO对象:
public class ProjectDto
{
public Type StatusEnum { get; set; }
public Status CurrentStatus { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
分配值:
var project = new ProjectDto
{
CurrentStatus = Status.Active,
StatusEnum = typeof (Status)
};
var output = JsonConvert.SerializeObject(project);
Run Code Online (Sandbox Code Playgroud)
要从枚举中获取值,我使用:
Enum.GetNames(typeof(Status)) //To get the names in the enum
Enum.GetValues(typeof(Status)) //To get the values in the …
Run Code Online (Sandbox Code Playgroud) 我们正在使用gulp-karma插件来吞噬我们的测试和PhantomJS.我们在Windows上运行,PhantomJS是一个.exe文件.我们的测试文件已经增长,现在我们收到错误"spawn ENAMETOOLONG".从我从这个答案收集到的:https://github.com/dbushell/grunt-svg2png/issues/17对于Grunt来说问题是发送到PhantomJS的参数太大了.有没有人有类似问题或知道任何解决方法(除了必须将测试文件合并到更少的文件)?
错误信息:
[14:20:19] Starting Karma server...
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENAMETOOLONG
at errnoException (child_process.js:1001:11)
at Process.ChildProcess._handle.onexit (child_process.js:792:34)
Run Code Online (Sandbox Code Playgroud)