Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ArgumentToken.cs « CommandLine « Common « tools « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c93c63f961b52ad27794953a13eabccb3f5abc1c (plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Internal.CommandLine
{
    internal sealed class ArgumentToken
    {
        internal ArgumentToken(string modifier, string name, string value)
        {
            Modifier = modifier;
            Name = name;
            Value = value;
        }

        public string Modifier { get; private set; }

        public string Name { get; private set; }

        public string Value { get; private set; }

        public bool IsOption
        {
            get { return !string.IsNullOrEmpty(Modifier); }
        }

        public bool IsSeparator
        {
            get { return Name == @":" || Name == @"="; }
        }

        public bool HasValue
        {
            get { return !string.IsNullOrEmpty(Value); }
        }

        public bool IsMatched { get; private set; }

        public void MarkMatched()
        {
            IsMatched = true;
        }

        private bool Equals(ArgumentToken other)
        {
            return string.Equals(Modifier, other.Modifier) &&
                   string.Equals(Name, other.Name) &&
                   string.Equals(Value, other.Value);
        }

        public override bool Equals(object obj)
        {
            if (ReferenceEquals(obj, null))
                return false;

            if (ReferenceEquals(obj, this))
                return true;

            var other = obj as ArgumentToken;
            return !ReferenceEquals(other, null) && Equals(other);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                var hashCode = (Modifier != null ? Modifier.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Name != null ? Name.GetHashCode() : 0);
                hashCode = (hashCode * 397) ^ (Value != null ? Value.GetHashCode() : 0);
                return hashCode;
            }
        }

        public override string ToString()
        {
            return HasValue
                ? string.Format(@"{0}{1}:{2}", Modifier, Name, Value)
                : string.Format(@"{0}{1}", Modifier, Name);
        }
    }
}