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

TypeSystemEntityOrUnknown.cs « Pgo « Common « tools « coreclr « src - github.com/dotnet/runtime.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2a064ebf03209160bbdde936b61afe51255659dd (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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Internal.TypeSystem;

namespace Internal.Pgo
{
    public struct TypeSystemEntityOrUnknown : IEquatable<TypeSystemEntityOrUnknown>
    {
        public TypeSystemEntityOrUnknown(int unknownIndex)
        {
            _data = unknownIndex;
        }

        public TypeSystemEntityOrUnknown(TypeDesc type)
        {
            _data = type;
        }

        public TypeSystemEntityOrUnknown(MethodDesc method)
        {
            _data = method;
        }

        private readonly object _data;
        public TypeDesc AsType => _data as TypeDesc;
        public MethodDesc AsMethod => _data as MethodDesc;
        public FieldDesc AsField => _data as FieldDesc;
        public int AsUnknown => (!(_data is int)) || _data == null ? 0 : (int)_data;
        public bool IsNull => _data == null;
        public bool IsUnknown => _data is int;

        public bool Equals(TypeSystemEntityOrUnknown other)
        {
            if ((_data is int) && (other._data is int))
            {
                return other.AsUnknown == AsUnknown;
            }
            else
            {
                return ReferenceEquals(_data, other._data);
            }
        }

        public override int GetHashCode() => _data?.GetHashCode() ?? 0;

        public override bool Equals(object obj) => obj is TypeSystemEntityOrUnknown other && other.Equals(this);

        public override string ToString()
        {
            if (_data == null)
            {
                return "null";
            }

            if ((_data is int))
            {
                return $"UnknownType({(int)_data})";
            }

            return _data.ToString();
        }
    }
}