From 960cc8e3643211eed2e5a0276fce3d0b9bd2f9a8 Mon Sep 17 00:00:00 2001 From: Yik Teng Hie Date: Mon, 6 Feb 2023 16:55:34 +0800 Subject: [PATCH] MotorProfile record --- MvvmAppCore/Models/MotorProfile.cs | 23 ++++++++++++------- .../ViewModels/MotorProfileViewModel.cs | 12 ++++++++++ README.md | 6 +++++ 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/MvvmAppCore/Models/MotorProfile.cs b/MvvmAppCore/Models/MotorProfile.cs index a156531..32d803b 100644 --- a/MvvmAppCore/Models/MotorProfile.cs +++ b/MvvmAppCore/Models/MotorProfile.cs @@ -1,12 +1,19 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Text.Json.Serialization; namespace MvvmAppCore.Models { - internal class MotorProfile - { - } + public record MotorProfile { + + [property: JsonPropertyName("Motor Name")] + public string MotorName { get; set; } + + [property: JsonPropertyName("Motor No")] + public int MotorNo { get; set; } + + [property: JsonPropertyName("Type")] + public int Type { get; set; } + + [property: JsonPropertyName("UPR")] + public double Upr { get; set; } + }; } diff --git a/MvvmAppCore/ViewModels/MotorProfileViewModel.cs b/MvvmAppCore/ViewModels/MotorProfileViewModel.cs index b16ab69..62053a5 100644 --- a/MvvmAppCore/ViewModels/MotorProfileViewModel.cs +++ b/MvvmAppCore/ViewModels/MotorProfileViewModel.cs @@ -1,4 +1,6 @@ using CommunityToolkit.Mvvm.ComponentModel; +using MvvmAppCore.Models; +using System; namespace MvvmAppCore.ViewModels { @@ -7,9 +9,19 @@ namespace MvvmAppCore.ViewModels [ObservableProperty] private string _motorName; + private MotorProfile _motorProfile = new MotorProfile + { + MotorName = "Gantry", + MotorNo = 1, + Type = 2, + Upr = 232 + }; + public MotorProfileViewModel() { MotorName = "Elevator"; + + System.Console.WriteLine($"Motor Name : {_motorProfile.MotorName}"); } } } diff --git a/README.md b/README.md index 6c3f357..8084e7e 100644 --- a/README.md +++ b/README.md @@ -20,3 +20,9 @@ Thus, this will minimize the amount of boiler code need to write. - Most doumentation is based on UWP. Thus, some syntax is not compatible - UWP & WinUI3 can use `{x:Bind ...}`. WPF no applicable. Need to use original `{Binding: ..}` syntax - Alternatively, [WPF x:Bind](https://github.com/levitali/CompiledBindings) nuget may help resolve this (TBA). + +## C# 9 +- [record](https://www.c-sharpcorner.com/article/c-sharp-9-0-introduction-to-record-types/) +- [Tutorial](https://www.infoq.com/articles/records-c9-tugce-ozdeger/) + - .NET 5 + - VS2019 and above \ No newline at end of file