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 ICSharpCode.NRefactory.CSharp.Resolver;
21
using ICSharpCode.NRefactory.Semantics;
22
using ICSharpCode.NRefactory.TypeSystem;
24
namespace ICSharpCode.NRefactory.CSharp.TypeSystem
27
/// Represents a reference which could point to a type or namespace.
30
public abstract class TypeOrNamespaceReference : ITypeReference
33
/// Resolves the reference and returns the ResolveResult.
35
public abstract ResolveResult Resolve(CSharpResolver resolver);
38
/// Returns the type that is referenced; or an <c>UnknownType</c> if the type isn't found.
40
public abstract IType ResolveType(CSharpResolver resolver);
43
/// Returns the namespace that is referenced; or null if no such namespace is found.
45
public INamespace ResolveNamespace(CSharpResolver resolver)
47
NamespaceResolveResult nrr = Resolve(resolver) as NamespaceResolveResult;
48
return nrr != null ? nrr.Namespace : null;
51
IType ITypeReference.Resolve(ITypeResolveContext context)
53
// Strictly speaking, we might have to resolve the type in a nested compilation, similar
54
// to what we're doing with ConstantExpression.
55
// However, in almost all cases this will work correctly - if the resulting type is only available in the
56
// nested compilation and not in this, we wouldn't be able to map it anyways.
57
var ctx = context as CSharpTypeResolveContext;
59
ctx = new CSharpTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember);
61
return ResolveType(new CSharpResolver(ctx));
63
// A potential issue might be this scenario:
66
// class A { public class Nested {} }
68
// Assembly 2: (references asm 1)
71
// Assembly 3: (references asm 1 and 2)
72
// class C { public B.Nested Field; }
74
// Assembly 4: (references asm 1 and 3, but not 2):
77
// Here we would not be able to resolve 'B.Nested' in the compilation of assembly 4, as type B is missing there.