// remove static methods (T.ReferenceEquals() is not possible)
        public override List <IMethod> GetMethods()
        {
            List <IMethod> list = base.GetMethods();

            if (list != null)
            {
                list.RemoveAll(delegate(IMethod m) { return(m.IsStatic || m.IsConstructor); });
                if (typeParameter.HasConstructableConstraint || typeParameter.HasValueTypeConstraint)
                {
                    list.Add(new Constructor(ModifierEnum.Public, this,
                                             DefaultTypeParameter.GetDummyClassForTypeParameter(typeParameter)));
                }
            }
            return(list);
        }
        public override bool Equals(object obj)
        {
            DefaultTypeParameter tp = obj as DefaultTypeParameter;

            if (tp == null)
            {
                return(false);
            }
            if (tp.index != index)
            {
                return(false);
            }
            if (tp.name != name)
            {
                return(false);
            }
            if (tp.hasConstructableConstraint != hasConstructableConstraint)
            {
                return(false);
            }
            if (tp.hasReferenceTypeConstraint != hasReferenceTypeConstraint)
            {
                return(false);
            }
            if (tp.hasValueTypeConstraint != hasValueTypeConstraint)
            {
                return(false);
            }
            if (tp.method != method)
            {
                if (tp.method == null || method == null)
                {
                    return(false);
                }
                if (tp.method.FullyQualifiedName != method.FullyQualifiedName)
                {
                    return(false);
                }
            }
            else
            {
                if (tp.targetClass.FullyQualifiedName != targetClass.FullyQualifiedName)
                {
                    return(false);
                }
            }
            return(true);
        }
示例#3
0
 static void AddTypeParametersForCtrlSpace(ArrayList result, IEnumerable <ITypeParameter> typeParameters)
 {
     foreach (ITypeParameter p in typeParameters)
     {
         DefaultClass c = DefaultTypeParameter.GetDummyClassForTypeParameter(p);
         if (p.Method != null)
         {
             c.Documentation = "Type parameter of " + p.Method.Name;
         }
         else
         {
             c.Documentation = "Type parameter of " + p.Class.Name;
         }
         result.Add(c);
     }
 }
示例#4
0
		void ConvertConstraints(NRefactoryAST.TemplateDefinition template, DefaultTypeParameter typeParameter)
		{
			foreach (NRefactoryAST.TypeReference typeRef in template.Bases) {
				if (typeRef == NRefactoryAST.TypeReference.NewConstraint) {
					typeParameter.HasConstructableConstraint = true;
				} else if (typeRef == NRefactoryAST.TypeReference.ClassConstraint) {
					typeParameter.HasReferenceTypeConstraint = true;
				} else if (typeRef == NRefactoryAST.TypeReference.StructConstraint) {
					typeParameter.HasValueTypeConstraint = true;
				} else {
					IReturnType rt = CreateReturnType(typeRef, typeParameter.Method, TypeVisitor.ReturnTypeOptions.None);
					if (rt != null) {
						typeParameter.Constraints.Add(rt);
					}
				}
			}
		}
示例#5
0
		void ConvertTemplates(DefaultClass outerClass, IList<NRefactoryAST.TemplateDefinition> templateList, DefaultClass c)
		{
			int outerClassTypeParameterCount = outerClass != null ? outerClass.TypeParameters.Count : 0;
			if (templateList.Count == 0 && outerClassTypeParameterCount == 0) {
				c.TypeParameters = DefaultTypeParameter.EmptyTypeParameterList;
			} else {
				Debug.Assert(c.TypeParameters.Count == 0);
				
				int index = 0;
				if (outerClassTypeParameterCount > 0) {
					foreach (DefaultTypeParameter outerTypeParamter in outerClass.TypeParameters) {
						DefaultTypeParameter p = new DefaultTypeParameter(c, outerTypeParamter.Name, index++);
						p.HasConstructableConstraint = outerTypeParamter.HasConstructableConstraint;
						p.HasReferenceTypeConstraint = outerTypeParamter.HasReferenceTypeConstraint;
						p.HasValueTypeConstraint = outerTypeParamter.HasValueTypeConstraint;
						p.Attributes.AddRange(outerTypeParamter.Attributes);
						p.Constraints.AddRange(outerTypeParamter.Constraints);
						c.TypeParameters.Add(p);
					}
				}
				
				foreach (NRefactoryAST.TemplateDefinition template in templateList) {
					c.TypeParameters.Add(new DefaultTypeParameter(c, template.Name, index++));
				}
				// converting the constraints requires that the type parameters are already present
				for (int i = 0; i < templateList.Count; i++) {
					ConvertConstraints(templateList[i], (DefaultTypeParameter)c.TypeParameters[i + outerClassTypeParameterCount]);
				}
			}
		}
示例#6
0
		GenericReturnType CreateT()
		{
			ITypeParameter tp = new DefaultTypeParameter(methodForGenericCalls, "T", 0);
			return new GenericReturnType(tp);
		}