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

ClassificationTypeImpl.cs « ClassificationType « Impl « Text « src - github.com/microsoft/vs-editor-api.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5a47305d0cec1d1e00aa21c88cf75607a8afac73 (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
//
//  Copyright (c) Microsoft Corporation. All rights reserved.
//  Licensed under the MIT License. See License.txt in the project root for license information.
//
// This file contain implementations details that are subject to change without notice.
// Use at your own risk.
//
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.Text.Utilities;

namespace Microsoft.VisualStudio.Text.Classification.Implementation
{
    internal class ClassificationTypeImpl : IClassificationType
    {
        private string name;
        private FrugalList<IClassificationType> baseTypes;

        internal ClassificationTypeImpl(string name)
        {
            this.name = name;
        }

        internal void AddBaseType(IClassificationType baseType)
        {
            if (this.baseTypes == null)
            {
                this.baseTypes = new FrugalList<IClassificationType>();
            }

            this.baseTypes.Add(baseType);
        }

        public string Classification
        {
            get { return this.name; }
        }

        public bool IsOfType(string type)
        {
            if (string.Equals(this.name, type, System.StringComparison.Ordinal))
                return true;
            else if (this.baseTypes != null)
            {
                foreach (IClassificationType baseType in this.baseTypes)
                {
                    if ( baseType.IsOfType(type) )
                        return true;
                }
            }

            return false;
        }

        public IEnumerable<IClassificationType> BaseTypes
        {
            get { return (this.baseTypes != null) ? (IEnumerable<IClassificationType>)(this.baseTypes.AsReadOnly()) : Enumerable.Empty<IClassificationType>(); }
        }

        public override string ToString()
        {
            return this.name;
        }
    }
}