码迷,mamicode.com
首页 > Windows程序 > 详细

PSObject 转 C# Object

时间:2021-04-19 14:38:49      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:output   object   value   tput   val   set   style   rop   var   

public class MyInfo
{
    public string Name { get; set; }
    public double Diff { get; set; }
    public string File { get; set; }
}

static void Main(string[] args)
{
    PSObject obj = PSObject.AsPSObject(new { Name = "David", Diff = 0.2, File = "output.txt" });

    var serialized = JsonConvert.SerializeObject(obj.Properties.ToDictionary(k => k.Name, v => v.Value));
    Console.WriteLine(serialized);

    var deseialized = JsonConvert.DeserializeObject<MyInfo>(serialized);
    Console.WriteLine($"Name: {deseialized.Name}");
    Console.WriteLine($"Diff: {deseialized.Diff}");
    Console.WriteLine($"File: {deseialized.File}");
}

 

PSObject 转 C# Object

标签:output   object   value   tput   val   set   style   rop   var   

原文地址:https://www.cnblogs.com/nanfei/p/14666776.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!