1
// Copyright (c) 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 namespace that is referenced; or null if no such namespace is found.
40
public INamespace ResolveNamespace(CSharpResolver resolver)
42
NamespaceResolveResult nrr = Resolve(resolver) as NamespaceResolveResult;
43
return nrr != null ? nrr.Namespace : null;
47
/// Returns the type that is referenced; or <see cref="SpecialType.UnknownType"/> if the type isn't found.
49
public IType ResolveType(CSharpResolver resolver)
51
TypeResolveResult trr = Resolve(resolver) as TypeResolveResult;
52
return trr != null ? trr.Type : SpecialType.UnknownType;
55
IType ITypeReference.Resolve(ITypeResolveContext context)
57
// Strictly speaking, we might have to resolve the type in a nested compilation, similar
58
// to what we're doing with ConstantExpression.
59
// However, in almost all cases this will work correctly - if the resulting type is only available in the
60
// nested compilation and not in this, we wouldn't be able to map it anyways.
61
var ctx = context as CSharpTypeResolveContext;
63
ctx = new CSharpTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember);
65
return ResolveType(new CSharpResolver(ctx));
67
// A potential issue might be this scenario:
70
// class A { public class Nested {} }
72
// Assembly 2: (references asm 1)
75
// Assembly 3: (references asm 1 and 2)
76
// class C { public B.Nested Field; }
78
// Assembly 4: (references asm 1 and 3, but not 2):
81
// Here we would not be able to resolve 'B.Nested' in the compilation of assembly 4, as type B is missing there.