Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CodeEditor/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory-5.5.0/TypeSystem/SpecialType.cs @ 11700

Last change on this file since 11700 was 11700, checked in by jkarder, 9 years ago

#2077: created branch and added first version

File size: 3.6 KB
Line 
1// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4// software and associated documentation files (the "Software"), to deal in the Software
5// without restriction, including without limitation the rights to use, copy, modify, merge,
6// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7// to whom the Software is furnished to do so, subject to the following conditions:
8//
9// The above copyright notice and this permission notice shall be included in all copies or
10// substantial portions of the Software.
11//
12// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17// DEALINGS IN THE SOFTWARE.
18
19using System;
20using System.Collections.Generic;
21using ICSharpCode.NRefactory.TypeSystem.Implementation;
22
23namespace ICSharpCode.NRefactory.TypeSystem
24{
25  /// <summary>
26  /// Contains static implementations of special types.
27  /// </summary>
28  [Serializable]
29  public sealed class SpecialType : AbstractType, ITypeReference
30  {
31    /// <summary>
32    /// Gets the type representing resolve errors.
33    /// </summary>
34    public readonly static SpecialType UnknownType = new SpecialType(TypeKind.Unknown, "?", isReferenceType: null);
35   
36    /// <summary>
37    /// The null type is used as type of the null literal. It is a reference type without any members; and it is a subtype of all reference types.
38    /// </summary>
39    public readonly static SpecialType NullType = new SpecialType(TypeKind.Null, "null", isReferenceType: true);
40   
41    /// <summary>
42    /// Type representing the C# 'dynamic' type.
43    /// </summary>
44    public readonly static SpecialType Dynamic = new SpecialType(TypeKind.Dynamic, "dynamic", isReferenceType: true);
45   
46    /// <summary>
47    /// A type used for unbound type arguments in partially parameterized types.
48    /// </summary>
49    /// <see cref="IType.GetNestedTypes(Predicate{ITypeDefinition}, GetMemberOptions)"/>
50    public readonly static SpecialType UnboundTypeArgument = new SpecialType(TypeKind.UnboundTypeArgument, "", isReferenceType: null);
51   
52    readonly TypeKind kind;
53    readonly string name;
54    readonly bool? isReferenceType;
55   
56    private SpecialType(TypeKind kind, string name, bool? isReferenceType)
57    {
58      this.kind = kind;
59      this.name = name;
60      this.isReferenceType = isReferenceType;
61    }
62   
63    public override ITypeReference ToTypeReference()
64    {
65      return this;
66    }
67   
68    public override string Name {
69      get { return name; }
70    }
71   
72    public override TypeKind Kind {
73      get { return kind; }
74    }
75   
76    public override bool? IsReferenceType {
77      get { return isReferenceType; }
78    }
79   
80    IType ITypeReference.Resolve(ITypeResolveContext context)
81    {
82      if (context == null)
83        throw new ArgumentNullException("context");
84      return this;
85    }
86   
87    #pragma warning disable 809
88    [Obsolete("Please compare special types using the kind property instead.")]
89    public override bool Equals(IType other)
90    {
91      // We consider a special types equal when they have equal types.
92      // However, an unknown type with additional information is not considered to be equal to the SpecialType with TypeKind.Unknown.
93      return other is SpecialType && other.Kind == kind;
94    }
95   
96    public override int GetHashCode()
97    {
98      return 81625621 ^ (int)kind;
99    }
100  }
101}
Note: See TracBrowser for help on using the repository browser.