/
githubmirror
/
PowerToys
Обзор
Документация
Войти
/
githubmirror
/
PowerToys
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/modules/EnvironmentVariables/EnvironmentVariablesUILib/Models/VariablesSet.cs
64 строки
2 KB
Dave Rayment
[EnvironmentVariables] Validation fixes, centralised validation, error message improvements (#46837)
05 авг 2026, 11:42
Не верифицирован
05 авг 2026, 11:42
3079a3c
Код
Авторство
О чём код?
// Copyright (c) Microsoft Corporation // The Microsoft Corporation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System; using System.Collections.ObjectModel; using System.Text.Json.Serialization; using CommunityToolkit.Mvvm.ComponentModel; namespace EnvironmentVariablesUILib.Models { public partial class VariablesSet : ObservableObject { public static readonly Guid UserGuid = new Guid("92F7AA9A-AE31-49CD-83C8-80A71E432AA5"); public static readonly Guid SystemGuid = new Guid("F679C74D-DB00-4795-92E1-B1F6A4833279"); private static readonly string UserIconPath = "/Assets/EnvironmentVariables/UserIcon.png"; private static readonly string SystemIconPath = "/Assets/EnvironmentVariables/SystemIcon.png"; protected static readonly string ProfileIconPath = "/Assets/EnvironmentVariables/ProfileIcon.png"; public Guid Id { get; set; } [ObservableProperty] [NotifyPropertyChangedFor(nameof(Valid))] private string _name; [JsonIgnore] public VariablesSetType Type { get; set; } [JsonIgnore] public string IconPath { get; set; } [ObservableProperty] private ObservableCollection<Variable> _variables; public bool Valid => Validate(); public VariablesSet() { } public VariablesSet(Guid id, string name, VariablesSetType type) { Id = id; Name = name; Type = type; Variables = new ObservableCollection<Variable>(); IconPath = Type switch { VariablesSetType.User => UserIconPath, VariablesSetType.System => SystemIconPath, VariablesSetType.Profile => ProfileIconPath, _ => throw new NotImplementedException(), }; } private bool Validate() => Type == VariablesSetType.Profile ? Helpers.EnvironmentVariablesHelper.TryValidateProfileName(Name, out _) : !string.IsNullOrWhiteSpace(Name); } }