Free cookie consent management tool by TermsFeed Policy Generator

source: branches/CodeEditor/HeuristicLab.ExtLibs/HeuristicLab.NRefactory/5.5.0/NRefactory-5.5.0/TypeSystem/Implementation/UnknownType.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.7 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.Diagnostics;
21
22namespace ICSharpCode.NRefactory.TypeSystem.Implementation
23{
24  /// <summary>
25  /// An unknown type where (part) of the name is known.
26  /// </summary>
27  [Serializable]
28  public class UnknownType : AbstractType, ITypeReference
29  {
30    readonly bool namespaceKnown;
31    readonly FullTypeName fullTypeName;
32   
33    /// <summary>
34    /// Creates a new unknown type.
35    /// </summary>
36    /// <param name="namespaceName">Namespace name, if known. Can be null if unknown.</param>
37    /// <param name="name">Name of the type, must not be null.</param>
38    /// <param name="typeParameterCount">Type parameter count, zero if unknown.</param>
39    public UnknownType(string namespaceName, string name, int typeParameterCount = 0)
40    {
41      if (name == null)
42        throw new ArgumentNullException("name");
43      this.namespaceKnown = namespaceName != null;
44      this.fullTypeName = new TopLevelTypeName(namespaceName ?? string.Empty, name, typeParameterCount);
45    }
46   
47    /// <summary>
48    /// Creates a new unknown type.
49    /// </summary>
50    /// <param name="fullTypeName">Full name of the unknown type.</param>
51    public UnknownType(FullTypeName fullTypeName)
52    {
53      if (fullTypeName.Name == null) {
54        Debug.Assert(fullTypeName == default(FullTypeName));
55        this.namespaceKnown = false;
56        this.fullTypeName = new TopLevelTypeName(string.Empty, "?", 0);
57      } else {
58        this.namespaceKnown = true;
59        this.fullTypeName = fullTypeName;
60      }
61    }
62   
63    public override TypeKind Kind {
64      get { return TypeKind.Unknown; }
65    }
66   
67    public override ITypeReference ToTypeReference()
68    {
69      return this;
70    }
71   
72    IType ITypeReference.Resolve(ITypeResolveContext context)
73    {
74      if (context == null)
75        throw new ArgumentNullException("context");
76      return this;
77    }
78   
79    public override string Name {
80      get { return fullTypeName.Name; }
81    }
82   
83    public override string Namespace {
84      get { return fullTypeName.TopLevelTypeName.Namespace; }
85    }
86   
87    public override string ReflectionName {
88      get { return namespaceKnown ? fullTypeName.ReflectionName : "?"; }
89    }
90   
91    public override int TypeParameterCount {
92      get { return fullTypeName.TypeParameterCount; }
93    }
94   
95    public override bool? IsReferenceType {
96      get { return null; }
97    }
98   
99    public override int GetHashCode()
100    {
101      return (namespaceKnown ? 812571 : 12651) ^ fullTypeName.GetHashCode();
102    }
103   
104    public override bool Equals(IType other)
105    {
106      UnknownType o = other as UnknownType;
107      if (o == null)
108        return false;
109      return this.namespaceKnown == o.namespaceKnown && this.fullTypeName == o.fullTypeName;
110    }
111   
112    public override string ToString()
113    {
114      return "[UnknownType " + fullTypeName.ReflectionName + "]";
115    }
116  }
117}
Note: See TracBrowser for help on using the repository browser.