/// <summary>
 /// Get any constraints for the specified <see cref="TypeParameter"/> on this method, or on the base virtual method if this method is an override.
 /// </summary>
 public List <TypeParameterConstraint> GetTypeParameterConstraints(TypeParameter typeParameter)
 {
     // Override methods don't specify constraints - they inherit them from the base virtual method.
     // In order to handle invalid code, just look in the first occurrence of constraints, searching
     // any base method if the current one is an override.
     if (_constraintClauses != null && _constraintClauses.Count > 0)
     {
         foreach (ConstraintClause constraintClause in _constraintClauses)
         {
             if (constraintClause.TypeParameter.Reference == typeParameter)
             {
                 return(constraintClause.Constraints);
             }
         }
     }
     else
     {
         MethodRef baseMethodRef = FindBaseMethod();
         if (baseMethodRef != null)
         {
             // If the constraints are from a base method, we have to translate the type parameter
             int index = FindTypeParameterIndex(typeParameter);
             TypeParameterRef typeParameterRef = baseMethodRef.GetTypeParameter(index);
             return(baseMethodRef.GetTypeParameterConstraints(typeParameterRef));
         }
     }
     return(null);
 }
Пример #2
0
        /// <summary>
        /// Determine if the current reference refers to the same code object as the specified reference.
        /// </summary>
        public override bool IsSameRef(SymbolicRef symbolicRef)
        {
            if (!(symbolicRef is TypeParameterRef))
            {
                return(false);
            }

            TypeParameterRef typeParameterRef          = (TypeParameterRef)symbolicRef;
            object           reference                 = GetReferencedType();
            object           typeParameterRefReference = typeParameterRef.GetReferencedType();

            if (reference != typeParameterRefReference)
            {
                // We also have to consider the references the same if the Name and NamespaceNames match.
                // This can occur when types are present both in an assembly reference, and also as CodeDOM
                // objects (either in the current project, or a referenced project).  This can occur if one
                // or both types are in a project with assembly references instead of project references to
                // a type that is defined in the current solution, which isn't uncommon - it will occur in
                // "master" solutions that include projects that are also used in other solutions, and also
                // if a project in the solution uses a non-supported language and so is referenced by its
                // assembly.
                if (Name != typeParameterRef.Name || NamespaceName != typeParameterRef.NamespaceName)
                {
                    return(false);
                }

                // With type parameters, the declaring (parent) type names must also match for the type
                // parameters to be considered the same.
                string declaringTypeName = GetDeclaringTypeOrMethodName(reference);
                string typeParameterRefDeclaringTypeName = typeParameterRef.GetDeclaringTypeOrMethodName();
                if (declaringTypeName == null || typeParameterRefDeclaringTypeName == null ||
                    declaringTypeName != typeParameterRefDeclaringTypeName)
                {
                    return(false);
                }
            }

            return(HasSameArrayRanks(typeParameterRef));
        }
Пример #3
0
 /// <summary>
 /// Create a <see cref="DocTypeParam"/>.
 /// </summary>
 public DocTypeParam(TypeParameterRef typeParameterRef, params DocComment[] docComments)
     : base(typeParameterRef, docComments)
 {
 }
Пример #4
0
 /// <summary>
 /// Create a <see cref="DocTypeParam"/>.
 /// </summary>
 public DocTypeParam(TypeParameterRef typeParameterRef, string text)
     : base(typeParameterRef, text)
 {
 }
 /// <summary>
 /// Create a <see cref="DocTypeParamRef"/>.
 /// </summary>
 public DocTypeParamRef(TypeParameterRef typeParameterRef)
     : base(typeParameterRef, (string)null)
 {
 }
 /// <summary>
 /// Create a <see cref="ConstraintClause"/>.
 /// </summary>
 public ConstraintClause(TypeParameterRef typeParameterRef, params TypeParameterConstraint[] constraints)
     : this((SymbolicRef)typeParameterRef, constraints)
 {
 }