// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Collections.Generic; using System.Collections.Immutable; using Microsoft.CodeAnalysis.PooledObjects; using Roslyn.Utilities; 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 { return TypeKind.Dynamic; } } public override ImmutableArray Locations { get { return ImmutableArray.Empty; } } public override ImmutableArray DeclaringSyntaxReferences { get { return ImmutableArray.Empty; } } internal override NamedTypeSymbol GetBaseTypeNoUseSiteDiagnostics(bool ignoreNonNullTypesAttribute) { return null; } internal override ImmutableArray InterfacesNoUseSiteDiagnostics(ConsList basesBeingResolved) { return ImmutableArray.Empty; } public override bool IsStatic { get { return false; } } public override bool IsValueType { get { return false; } } internal sealed override bool IsManagedType { get { return true; } } internal sealed override bool IsByRefLikeType { get { return false; } } internal sealed override bool IsReadOnly { get { return false; } } internal sealed override ObsoleteAttributeData ObsoleteAttributeData { get { return null; } } public override ImmutableArray GetMembers() { return ImmutableArray.Empty; } public override ImmutableArray GetMembers(string name) { return ImmutableArray.Empty; } public override ImmutableArray GetTypeMembers(string name) { return ImmutableArray.Empty; } public override ImmutableArray GetTypeMembers() { return ImmutableArray.Empty; } internal override TResult Accept(CSharpSymbolVisitor visitor, TArgument argument) { return visitor.VisitDynamicType(this, argument); } public override void Accept(CSharpSymbolVisitor visitor) { visitor.VisitDynamicType(this); } public override TResult Accept(CSharpSymbolVisitor 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 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; } internal override bool Equals(TypeSymbol t2, TypeCompareKind comparison) { if ((object)t2 == null) { return false; } if (ReferenceEquals(this, t2) || t2.TypeKind == TypeKind.Dynamic) { return true; } if ((comparison & TypeCompareKind.IgnoreDynamic) != 0) { var other = t2 as NamedTypeSymbol; return (object)other != null && other.SpecialType == Microsoft.CodeAnalysis.SpecialType.System_Object; } return false; } internal override bool ContainsNullableReferenceTypes() { return false; } internal override void AddNullableTransforms(ArrayBuilder transforms) { } internal override bool ApplyNullableTransforms(ImmutableArray transforms, bool useNonNullTypes, ref int position, out TypeSymbol result) { result = this; return true; } internal override TypeSymbol SetUnknownNullabilityForReferenceTypes() { return this; } #region ISymbol Members public override void Accept(SymbolVisitor visitor) { visitor.VisitDynamicType(this); } public override TResult Accept(SymbolVisitor visitor) { return visitor.VisitDynamicType(this); } #endregion } }