using System; using System.Text.Json; using System.Text.Json.Serialization; namespace Kean.Application.Command.ViewModels { /// /// 密码视图 /// public sealed class Password : JsonConverter { /// /// 标识 /// public int Id { get; set; } /// /// 当前密码 /// public string Current { get; set; } /// /// 新密码 /// public string Replacement { get; set; } /// /// 返回当前密码字符串 /// public override string ToString() => Current; /// /// Json 序列化 /// public override void Write(Utf8JsonWriter writer, Password value, JsonSerializerOptions options) => writer.WriteStringValue(value); /// /// Json 反序列化 /// public override Password Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) => reader.GetString(); /// /// 从字符串隐式转换 /// public static implicit operator Password(string password) => new() { Current = password }; /// /// 隐式转换为字符串 /// public static implicit operator string(Password password) => password.Current; } }