DynamicTypeSymbol.cs 6.3 KB
Newer Older
1
// Copyright (c) Microsoft.  All Rights Reserved.  Licensed under the Apache License, Version 2.0.  See License.txt in the project root for license information.
P
Pilchie 已提交
2

3
using System;
P
Pilchie 已提交
4 5
using System.Collections.Generic;
using System.Collections.Immutable;
6
using Microsoft.CodeAnalysis.PooledObjects;
7
using Roslyn.Utilities;
P
Pilchie 已提交
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

namespace Microsoft.CodeAnalysis.CSharp.Symbols
{
    internal sealed partial class DynamicTypeSymbol : TypeSymbol, IDynamicTypeSymbol
    {
        internal static readonly DynamicTypeSymbol Instance = new DynamicTypeSymbol();

        private DynamicTypeSymbol()
        {
        }

        public override string Name
        {
            get
            {
                return "dynamic";
            }
        }

        public override bool IsAbstract
        {
            get
            {
                return false;
            }
        }

        public override bool IsReferenceType
        {
            get
            {
                return true;
            }
        }

        public override bool IsSealed
        {
            get
            {
                return false;
            }
        }

        public override SymbolKind Kind
        {
            get
            {
                return SymbolKind.DynamicType;
            }
        }

        public override TypeKind TypeKind
        {
            get
            {
63
                return TypeKind.Dynamic;
P
Pilchie 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
            }
        }

        public override ImmutableArray<Location> Locations
        {
            get
            {
                return ImmutableArray<Location>.Empty;
            }
        }

        public override ImmutableArray<SyntaxReference> DeclaringSyntaxReferences
        {
            get
            {
                return ImmutableArray<SyntaxReference>.Empty;
            }
        }

83
        internal override NamedTypeSymbol GetBaseTypeNoUseSiteDiagnostics(bool ignoreNonNullTypesAttribute)
P
Pilchie 已提交
84
        {
85
            return null;
P
Pilchie 已提交
86 87
        }

88
        internal override ImmutableArray<NamedTypeSymbol> InterfacesNoUseSiteDiagnostics(ConsList<Symbol> basesBeingResolved)
P
Pilchie 已提交
89
        {
90
            return ImmutableArray<NamedTypeSymbol>.Empty;
P
Pilchie 已提交
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
        }

        public override bool IsStatic
        {
            get
            {
                return false;
            }
        }

        public override bool IsValueType
        {
            get
            {
                return false;
            }
        }

        internal sealed override bool IsManagedType
        {
            get
            {
                return true;
            }
        }

V
vsadov 已提交
117 118 119 120
        internal sealed override bool IsByRefLikeType
        {
            get
            {
V
vsadov 已提交
121 122 123 124 125 126 127 128
                return false;
            }
        }

        internal sealed override bool IsReadOnly
        {
            get
            {
V
vsadov 已提交
129 130 131 132
                return false;
            }
        }

P
Pilchie 已提交
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
        internal sealed override ObsoleteAttributeData ObsoleteAttributeData
        {
            get { return null; }
        }

        public override ImmutableArray<Symbol> GetMembers()
        {
            return ImmutableArray<Symbol>.Empty;
        }

        public override ImmutableArray<Symbol> GetMembers(string name)
        {
            return ImmutableArray<Symbol>.Empty;
        }

        public override ImmutableArray<NamedTypeSymbol> GetTypeMembers(string name)
        {
            return ImmutableArray<NamedTypeSymbol>.Empty;
        }

        public override ImmutableArray<NamedTypeSymbol> GetTypeMembers()
        {
            return ImmutableArray<NamedTypeSymbol>.Empty;
        }

        internal override TResult Accept<TArgument, TResult>(CSharpSymbolVisitor<TArgument, TResult> visitor, TArgument argument)
        {
            return visitor.VisitDynamicType(this, argument);
        }

        public override void Accept(CSharpSymbolVisitor visitor)
        {
            visitor.VisitDynamicType(this);
        }

        public override TResult Accept<TResult>(CSharpSymbolVisitor<TResult> visitor)
        {
            return visitor.VisitDynamicType(this);
        }

        public override Symbol ContainingSymbol
        {
            get
            {
                return null;
            }
        }

        public override Accessibility DeclaredAccessibility
        {
            get
            {
                return Accessibility.NotApplicable;
            }
        }

        internal override bool GetUnificationUseSiteDiagnosticRecursive(ref DiagnosticInfo result, Symbol owner, ref HashSet<TypeSymbol> checkedTypes)
        {
            return false;
        }

        public override int GetHashCode()
        {
            // return the distinguished value for 'object' because the hash code ignores the distinction
            // between dynamic and object.  It also ignores custom modifiers.
            return (int)Microsoft.CodeAnalysis.SpecialType.System_Object;
        }

201
        internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison)
P
Pilchie 已提交
202 203 204 205 206 207
        {
            if ((object)t2 == null)
            {
                return false;
            }

208
            if (ReferenceEquals(this, t2) || t2.TypeKind == TypeKind.Dynamic)
P
Pilchie 已提交
209 210 211 212
            {
                return true;
            }

213
            if ((comparison & TypeCompareKind.IgnoreDynamic) != 0)
P
Pilchie 已提交
214 215 216 217 218 219 220 221
            {
                var other = t2 as NamedTypeSymbol;
                return (object)other != null && other.SpecialType == Microsoft.CodeAnalysis.SpecialType.System_Object;
            }

            return false;
        }

222 223 224 225 226 227 228 229 230
        internal override bool ContainsNullableReferenceTypes()
        {
            return false;
        }

        internal override void AddNullableTransforms(ArrayBuilder<bool> transforms)
        {
        }

231
        internal override bool ApplyNullableTransforms(ImmutableArray<bool> transforms, bool useNonNullTypes, ref int position, out TypeSymbol result)
232 233 234 235 236
        {
            result = this;
            return true;
        }

237
        internal override TypeSymbol SetUnknownNullabilityForReferenceTypes()
238 239 240 241
        {
            return this;
        }

P
Pilchie 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255
        #region ISymbol Members

        public override void Accept(SymbolVisitor visitor)
        {
            visitor.VisitDynamicType(this);
        }

        public override TResult Accept<TResult>(SymbolVisitor<TResult> visitor)
        {
            return visitor.VisitDynamicType(this);
        }

        #endregion
    }
256
}