1
// Copyright (c) 2010-2013 AlphaSierraPapa for the SharpDevelop Team
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:
9
// The above copyright notice and this permission notice shall be included in all copies or
10
// substantial portions of the Software.
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.
20
using System.Diagnostics;
22
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
25
/// An unknown type where (part) of the name is known.
28
public class UnknownType : AbstractType, ITypeReference
30
readonly bool namespaceKnown;
31
readonly FullTypeName fullTypeName;
34
/// Creates a new unknown type.
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)
42
throw new ArgumentNullException("name");
43
this.namespaceKnown = namespaceName != null;
44
this.fullTypeName = new TopLevelTypeName(namespaceName ?? string.Empty, name, typeParameterCount);
48
/// Creates a new unknown type.
50
/// <param name="fullTypeName">Full name of the unknown type.</param>
51
public UnknownType(FullTypeName fullTypeName)
53
if (fullTypeName.Name == null) {
54
Debug.Assert(fullTypeName == default(FullTypeName));
55
this.namespaceKnown = false;
56
this.fullTypeName = new TopLevelTypeName(string.Empty, "?", 0);
58
this.namespaceKnown = true;
59
this.fullTypeName = fullTypeName;
63
public override TypeKind Kind {
64
get { return TypeKind.Unknown; }
67
public override ITypeReference ToTypeReference()
72
IType ITypeReference.Resolve(ITypeResolveContext context)
75
throw new ArgumentNullException("context");
79
public override string Name {
80
get { return fullTypeName.Name; }
83
public override string Namespace {
84
get { return fullTypeName.TopLevelTypeName.Namespace; }
87
public override string ReflectionName {
88
get { return namespaceKnown ? fullTypeName.ReflectionName : "?"; }
91
public override int TypeParameterCount {
92
get { return fullTypeName.TypeParameterCount; }
95
public override bool? IsReferenceType {
99
public override int GetHashCode()
101
return (namespaceKnown ? 812571 : 12651) ^ fullTypeName.GetHashCode();
104
public override bool Equals(IType other)
106
UnknownType o = other as UnknownType;
109
return this.namespaceKnown == o.namespaceKnown && this.fullTypeName == o.fullTypeName;
112
public override string ToString()
114
return "[UnknownType " + fullTypeName.ReflectionName + "]";