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

EditorOptionKey.cs « EditorOptions « TextLogic « Def « Text « src - github.com/microsoft/vs-editor-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c9f1cfa7c342d53f2ddd3e09e96415e50d05b90 (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
81
82
83
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License. See License.txt in the project root for license information.
//
namespace Microsoft.VisualStudio.Text.Editor
{
    /// <summary>
    /// Represents a type-safe key for editor options.
    /// </summary>
    /// <typeparam name="T">The type of the option value.</typeparam>
    public struct EditorOptionKey<T>
    {
        #region Private data
        private string _name;
        #endregion

        /// <summary>
        /// Initializes a new instance of <see cref="EditorOptionKey&lt;T&gt;"/>.
        /// </summary>
        /// <param name="name">The name of the option key.</param>
        public EditorOptionKey(string name) { _name = name; }

        /// <summary>
        /// Gets the name of this key.
        /// </summary>
        public string Name { get { return _name; } }

        #region Object overrides

        /// <summary>
        /// Determines whether two <see cref="EditorOptionKey&lt;T&gt;"/> objects are the same.
        /// </summary>
        /// <param name="obj">The object to be compared.</param>
        /// <returns><c>true</c> if the objects are the same, otherwise <c>false</c>.</returns>
        public override bool Equals(object obj)
        {
            if (obj is EditorOptionKey<T>)
            {
                EditorOptionKey<T> other = (EditorOptionKey<T>)obj;
                return other.Name == this.Name;
            }

            return false;
        }

        /// <summary>
        /// Gets the hash code for this object.
        /// </summary>
        /// <returns>The hash code.</returns>
        public override int GetHashCode()
        {
            return this.Name.GetHashCode();
        }

        /// <summary>
        /// Converts this object to a string. 
        /// </summary>
        /// <returns>The name of the option.</returns>
        public override string ToString()
        {
            return this.Name;
        }

        /// <summary>
        /// Determines whether two instances of this type are the same.
        /// </summary>
        public static bool operator ==(EditorOptionKey<T> left, EditorOptionKey<T> right)
        {
            return left.Name == right.Name;
        }

        /// <summary>
        /// Determines whether two instances of this type are different.
        /// </summary>
        public static bool operator !=(EditorOptionKey<T> left, EditorOptionKey<T> right)
        {
            return !(left == right);
        }

        #endregion
    }

}