1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
5
using System.Collections.Generic;
7
namespace ICSharpCode.SharpDevelop.Dom
10
/// GenericReturnType is a reference to a type parameter.
12
public sealed class GenericReturnType : DecoratingReturnType
14
ITypeParameter typeParameter;
16
public ITypeParameter TypeParameter {
22
public override bool Equals(IReturnType rt)
24
if (rt == null || !rt.IsGenericReturnType)
26
GenericReturnType grt = rt.CastToGenericReturnType();
27
if ((typeParameter.Method == null) != (grt.typeParameter.Method == null))
29
return typeParameter.Index == grt.typeParameter.Index;
32
public override int GetHashCode()
34
if (typeParameter.Method != null)
35
return 17491 + typeParameter.Index;
37
return 81871 + typeParameter.Index;
40
public override T CastToDecoratingReturnType<T>()
42
if (typeof(T) == typeof(GenericReturnType)) {
43
return (T)(object)this;
49
public GenericReturnType(ITypeParameter typeParameter)
51
if (typeParameter == null)
52
throw new ArgumentNullException("typeParameter");
53
this.typeParameter = typeParameter;
56
public override string FullyQualifiedName {
58
return typeParameter.Name;
62
public override string Name {
64
return typeParameter.Name;
68
public override string Namespace {
74
public override string DotNetName {
76
if (typeParameter.Method != null)
77
return "``" + typeParameter.Index;
79
return "`" + typeParameter.Index;
83
public override IClass GetUnderlyingClass()
88
public override IReturnType BaseType {
90
int count = typeParameter.Constraints.Count;
92
return typeParameter.Class.ProjectContent.SystemTypes.Object;
94
return typeParameter.Constraints[0];
95
return new CombinedReturnType(typeParameter.Constraints,
102
// remove static methods (T.ReferenceEquals() is not possible)
103
public override List<IMethod> GetMethods()
105
List<IMethod> list = base.GetMethods();
107
list.RemoveAll(delegate(IMethod m) { return m.IsStatic || m.IsConstructor; });
108
if (typeParameter.HasConstructableConstraint || typeParameter.HasValueTypeConstraint) {
109
list.Add(new Constructor(ModifierEnum.Public, this,
110
DefaultTypeParameter.GetDummyClassForTypeParameter(typeParameter)));
116
public override Nullable<bool> IsReferenceType {
120
public override string ToString()
122
return String.Format("[GenericReturnType: {0}]", typeParameter);