惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
Vercel News
Vercel News
C
Check Point Blog
G
Google Developers Blog
博客园 - 司徒正美
量子位
Engineering at Meta
Engineering at Meta
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
A
About on SuperTechFans
美团技术团队
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Cloudflare Blog
U
Unit 42

博客园 - FredGrit

WPF customize via three combied custom controls WPF DataGrid DataGridTemplateColumn DataTemplate ContentPresenter ContentTemplate WPF Customcontrol NumUpDownScroller WPF CustomControl override Template in Generic.xaml and invoke different style WPF HierarchicalDataTemplate customize via ToggleButton WPF DataGrid DataGridTemplateColumn DataTemplate call predefined DataTemplate via ContentPresenter and ContentTemplate WPF ListBox load data via contentcontrol an ItemTemplate WPF DataGrid load data from Asp.Net Core WebAPI WPF TreeView HierarchicalDataTemplate with grouped Data WPF display grouped data with GroupBox and ItemsControl WPF two listbox scroll syncchronously via behavior WPF invoke data from WebAPI,DataGridTemplate call pre defined DataTemplate via ContentPresenter WPF ListBox load data from WCF WPF datagrid load data from WCF via json, export selected items to json file WPF ItemsControl load data from WCF,DataTemplate, ContentControl WPF customize rotated wheel relentlessly via custom control WPF embed DataTemplate in HierchicalDataTemplate of TreeView WPF ContentControl, ItemsControl, ItemsPanelTemplate,VirtualizingStackPanel,convert xml string to List<T> WPF parse web.config recursively, TreeView and HierarchicalDataTemplate WPF Custom control in cs and Generic.xaml WPF ContextMenu independent visual tree resolved via Freezable implemented class WPF custom control GetTemplateChild vs FindName,NameScope separation between Logical Tree and Visual Tree, WPF ListBox ListView Datatemplate, parse xml to List via XmlSerializer and StringReader WPF TreeView HierarchicalDataTemplate, parse xml via traverse in XmlElement WPF parse xml via [XmRoot] and [XmlElement] attributes together, contentcontrol's template is ControlTemplate from Resources WPF ContentControl invoke Template from resource, reuse datatemplate WPF deserialize xml string as List via [XmlRoot] and [XmlElement] attribute WPF ContentControl Template WPF DatagridTemplate Binding DataTemplate WPF TreeView explicitly given key name to HierarchicalDataTemplate
C# serialize datetime then deserialize, print lose precis...
FredGrit · 2026-03-21 · via 博客园 - FredGrit
//Service
namespace WebApplication4.Models
{
    public class Book
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string ISBN { get; set;  }
        public string Author { get; set;  }
        public string Abstract { get; set; }
        public string Comment { get; set;  }    
        public string Content { get; set;  }
        public string Summary {  get; set; }
        public DateTime Time { get; set; }
        public string Title {  get; set; }
        public string Topic { get; set;  }
    }
}

using WebApplication4.Models;

namespace WebApplication4.Services
{
    public class BookService
    {
        private List<Book> booksList {  get; set; }
        public BookService()
        {
        }

        public List<Book> GetBooksList(int len = 10000)
        {
            booksList = new List<Book>();
            for (int a = 1; a < len + 1; a++)
            {
                booksList.Add(new Book()
                {
                    Id = a,
                    Name = $"Name_{a}",
                    ISBN = $"ISBN_{a}_{Guid.NewGuid():N}",
                    Abstract = $"Abstract_{a}",
                    Author = $"Author_{a}",
                    Comment = $"Comment_{a}",
                    Content = $"Content_{a}",
                    Summary = $"Summary_{a}",
                    Time = DateTime.Now,
                    Title = $"Title_{a}",
                    Topic = $"Topic_{a}"
                });
            }
            return booksList;
        }

        public Book? GetBooksById(int id)
        {
            return booksList.Where(x => x.Id == id)?.FirstOrDefault();
        }

    }
}
using Microsoft.AspNetCore.Mvc;
using WebApplication4.Models;
using WebApplication4.Services;

namespace WebApplication4.Controllers
{
    [ApiController]
    [Route("api/[controller]")]
    public class BookController : Controller
    {
        BookService bkService;
        public BookController(BookService bkServiceValue)
        {
            bkService = bkServiceValue;
        }
        [HttpGet("GetBooks")]
        [HttpGet("GetBooks2", Name = "GetBooks3")]
        [HttpGet("GetBooks4")]
        [HttpGet("GetBooks5")]
        [HttpGet("GetBooks6")]
        [HttpGet("GetBooks7")]
        public List<Book> GetBooks()
        {
            return bkService.GetBooksList();
        }

        [HttpGet("GetBook/{id}")]
        public Book? GetBookById(int id)
        {
            return bkService.GetBooksById(id);
        }         
    }
}

using WebApplication4.Controllers;
using WebApplication4.Services;

namespace WebApplication4
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.

            builder.Services.AddControllers();
            // Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
            builder.Services.AddOpenApi();
            builder.Services.AddSingleton<BookService>();
            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.MapOpenApi();
            }

            app.UseHttpsRedirection();

            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}


//client
using Newtonsoft.Json;

namespace ConsoleApp10
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            await GetBooksAsync();
        }

        static async Task GetBooksAsync()
        {
            string bookUrl = "https://localhost:7129/api/book/GetBooks2";
            using (HttpClient client = new HttpClient())
            {
                string jsonStr = await client.GetStringAsync(bookUrl);
                List<Book>? bksList=JsonConvert.DeserializeObject<List<Book>>(jsonStr);
                if (bksList != null && bksList.Any())
                {
                    foreach(var bk in bksList)
                    {
                        Console.WriteLine($"Id:{bk.Id},time:{bk.Time}");
                    }
                }
            }
        }


        public class Book
        {
            public int Id { get; set; }
            public string Name { get; set; }
            public string ISBN { get; set; }
            public string Author { get; set; }
            public string Abstract { get; set; }
            public string Comment { get; set; }
            public string Content { get; set; }
            public string Summary { get; set; }
            public DateTime Time { get; set; }
            public string Title { get; set; }
            public string Topic { get; set; }
        }
    }
}
Console.WriteLine($"Id:{bk.Id},time:{bk.Time}");
"time":"2026-03-21T00:06:56.4686857+08:00"
Id:1,time:2026-03-21 00:06:56
Console.WriteLine($"Id:{bk.Id},time:{bk.Time.ToString("O")}");
"time":"2026-03-21T00:07:57.6253803+08:00"
Id:1,time:2026-03-21T00:07:57.6253803+08:00

posted @ 2026-03-21 00:08  FredGrit  阅读(4)  评论()    收藏  举报