using System; using System.Collections.Generic; using System.ComponentModel; using System.Runtime.CompilerServices; namespace openF1Manager.scripts; /// /// An attribute that is applied to a property to associate it with a specific API field key. /// /// /// This attribute is used to map a class property to a corresponding field in the API. /// It allows specifying a key that identifies the corresponding API field. /// [AttributeUsage(AttributeTargets.Property)] public sealed class ApiFieldAttribute : Attribute { public string Key { get; } public ApiFieldAttribute(string key) => Key = key; } public partial class SessionFilter : INotifyPropertyChanged { private string? _meetingKey; private string? _sessionKey; private string? _location; private DateTime? _dateStart; private DateTime? _dateEnd; private string? _sessionType; private string? _sessionName; private int? _countryKey; private string? _countryCode; private string? _countryName; private int? _circuitKey; private string? _circuitShortName; private string? _gmtOffset; private string? _year; [ApiField("meeting_key")] public string MeetingKey { get => _meetingKey; set => SetField(ref _meetingKey, value); } [ApiField("session_key")] public string SessionKey { get => _sessionKey; set => SetField(ref _sessionKey, value); } [ApiField("location")] public string Location { get => _location; set => SetField(ref _location, value); } [ApiField("date_start")] public DateTime? DateStart { get => _dateStart; set => SetField(ref _dateStart, value); } [ApiField("date_en")] public DateTime? DateEnd { get => _dateEnd; set => SetField(ref _dateEnd, value); } [ApiField("session_type")] public string SessionType { get => _sessionType; set => SetField(ref _sessionType, value); } [ApiField("session_name")] public string SessionName { get => _sessionName; set => SetField(ref _sessionName, value); } [ApiField("country_key")] public int? CountryKey { get => _countryKey; set => SetField(ref _countryKey, value); } [ApiField("country_code")] public string CountryCode { get => _countryCode; set => SetField(ref _countryCode, value); } [ApiField("country_name")] public string CountryName { get => _countryName; set => SetField(ref _countryName, value); } [ApiField("circuit_key")] public int? CircuitKey { get => _circuitKey; set => SetField(ref _circuitKey, value); } [ApiField("circuit_short_name")] public string CircuitShortName { get => _circuitShortName; set => SetField(ref _circuitShortName, value); } [ApiField("gmt_offset")] public string GmtOffset { get => _gmtOffset; set => SetField(ref _gmtOffset, value); } [ApiField("year")] public string Year { get => _year; set => SetField(ref _year, value); } public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } protected bool SetField(ref T field, T value, [CallerMemberName] string propertyName = null) { if (EqualityComparer.Default.Equals(field, value)) return false; field = value; OnPropertyChanged(propertyName); return true; } }