/
dOJer113
/
Insect
Обзор
Документация
Войти
/
dOJer113
/
Insect
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
insects/Insect.cs
76 строк
2 KB
alex
Валидация
21 дек 2025, 20:06
21 дек 2025, 20:06
640f9dc
Код
Авторство
О чём код?
using System.ComponentModel.DataAnnotations; using System.Text.Json.Serialization; using CommunityToolkit.Mvvm.ComponentModel; namespace insects; /// <summary> /// Базовый класс насекомого с общими свойствами. /// </summary> public partial class Insect : ObservableValidator, ICloneable { [ObservableProperty] [Range(0, int.MaxValue)] private int _id; [ObservableProperty] [Required] [StringLength(64, MinimumLength = 2)] private string? _name; [ObservableProperty] private bool _hasWings; [ObservableProperty] [Required] [StringLength(32, MinimumLength = 2)] private string? _mouthpieceType; [ObservableProperty] private decimal _bodySize; [Required] [JsonPropertyName("typeName")] public virtual string TypeName => GetType().Name; [JsonIgnore] public string InsectTypeName => TypeName; public Insect() { Id = 0; Name = string.Empty; HasWings = true; MouthpieceType = "Жвалы"; BodySize = 1; } public Insect(string? name, bool hasWings, string? mouthpieceType, decimal bodySize) { Id = 0; Name = name; HasWings = hasWings; MouthpieceType = mouthpieceType; BodySize = bodySize; } public Insect(Insect other) { Id = other.Id; Name = other.Name; HasWings = other.HasWings; MouthpieceType = other.MouthpieceType; BodySize = other.BodySize; } public virtual void Assign(Insect other) { Id = other.Id; Name = other.Name; HasWings = other.HasWings; MouthpieceType = other.MouthpieceType; BodySize = other.BodySize; } public virtual object Clone() => new Insect(this); }