MotorProfile record

master
Yik Teng Hie 3 years ago
parent ea22a95348
commit 960cc8e364

@ -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; }
};
}

@ -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}");
}
}
}

@ -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
Loading…
Cancel
Save