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 System.Globalization;
22
namespace ICSharpCode.NRefactory.TypeSystem.Implementation
25
public sealed class TypeParameterReference : ITypeReference, ISupportsInterning
27
readonly EntityType ownerType;
30
public TypeParameterReference(EntityType ownerType, int index)
32
this.ownerType = ownerType;
36
public IType Resolve(ITypeResolveContext context)
38
if (ownerType == EntityType.Method) {
39
IMethod method = context.CurrentMember as IMethod;
40
if (method != null && index < method.TypeParameters.Count) {
41
return method.TypeParameters[index];
43
return DummyTypeParameter.GetMethodTypeParameter(index);
44
} else if (ownerType == EntityType.TypeDefinition) {
45
ITypeDefinition typeDef = context.CurrentTypeDefinition;
46
if (typeDef != null && index < typeDef.TypeParameters.Count) {
47
return typeDef.TypeParameters[index];
49
return DummyTypeParameter.GetClassTypeParameter(index);
51
return SpecialType.UnknownType;
55
void ISupportsInterning.PrepareForInterning(IInterningProvider provider)
59
int ISupportsInterning.GetHashCodeForInterning()
61
return index * 33 + (int)ownerType;
64
bool ISupportsInterning.EqualsForInterning(ISupportsInterning other)
66
TypeParameterReference r = other as TypeParameterReference;
67
return r != null && index == r.index && ownerType == r.ownerType;
70
public override string ToString()
72
if (ownerType == EntityType.Method)
73
return "!!" + index.ToString(CultureInfo.InvariantCulture);
75
return "!" + index.ToString(CultureInfo.InvariantCulture);