~ruther/NosTale-PacketLogger

ref: 39ccc8e1759ba341c324146a6268e55dd6d340a3 NosTale-PacketLogger/src/PacketLogger/Converters/PacketSourceConverter.cs -rw-r--r-- 1.4 KiB
39ccc8e1 — Rutherther fix: make no profile working correctly, changing to no profile on change 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
//  PacketSourceConverter.cs
//
//  Copyright (c) František Boháček. All rights reserved.
//  Licensed under the MIT license. See LICENSE file in the project root for full license information.

using System;
using System.Globalization;
using Avalonia.Data.Converters;
using NosSmooth.PacketSerializer.Abstractions.Attributes;

namespace PacketLogger.Converters;

/// <summary>
/// Converts <see cref="PacketSource"/>.
/// </summary>
public class PacketSourceConverter : IValueConverter
{
    /// <inheritdoc />
    public object? Convert
    (
        object? value,
        Type targetType,
        object? parameter,
        CultureInfo culture
    )
    {
        if (value is not PacketSource source)
        {
            throw new ArgumentException("Must be PacketSource.", nameof(value));
        }

        return source == PacketSource.Client ? "Send" : "Recv";
    }

    /// <inheritdoc />
    public object? ConvertBack
    (
        object? value,
        Type targetType,
        object? parameter,
        CultureInfo culture
    )
    {
        if (value is not string stringVal)
        {
            throw new ArgumentException("Must be string.", nameof(value));
        }

        if (stringVal == "Send")
        {
            return PacketSource.Client;
        }
        if (stringVal == "Recv")
        {
            return PacketSource.Server;
        }

        throw new ArgumentException("Must be \"Recv\" or \"Send\".");
    }
}
Do not follow this link