Esempio n. 1
0
 /// <summary>
 /// Gets the best common type (C# 4.0 spec: §7.5.2.14) of a set of expressions.
 /// </summary>
 public IType GetBestCommonType(IList <ResolveResult> expressions, out bool success)
 {
     if (expressions == null)
     {
         throw new ArgumentNullException("expressions");
     }
     if (expressions.Count == 1)
     {
         success = (expressions[0].Type.Kind != TypeKind.Unknown);
         return(expressions[0].Type);
     }
     Log.WriteCollection("GetBestCommonType() for ", expressions);
     try {
         ITypeParameter tp = DummyTypeParameter.GetMethodTypeParameter(0);
         this.typeParameters = new TP[1] {
             new TP(tp)
         };
         foreach (ResolveResult r in expressions)
         {
             MakeOutputTypeInference(r, tp);
         }
         success = Fix(typeParameters[0]);
         return(typeParameters[0].FixedTo ?? SpecialType.UnknownType);
     } finally {
         Reset();
     }
 }
        static bool CompareTypes(IType a, IType b)
        {
            IType type1 = DummyTypeParameter.NormalizeAllTypeParameters(a);
            IType type2 = DummyTypeParameter.NormalizeAllTypeParameters(b);

            return(type1.Equals(type2));
        }
Esempio n. 3
0
 public override IType VisitTypeParameter(ITypeParameter type)
 {
     if (type.OwnerType == EntityType.Method)
     {
         return(DummyTypeParameter.GetMethodTypeParameter(type.Index));
     }
     else
     {
         return(base.VisitTypeParameter(type));
     }
 }
Esempio n. 4
0
 public ITypeParameter GetMethodTypeParameter(int index)
 {
     if (index < MethodTypeParameters?.Count)
     {
         return(MethodTypeParameters[index]);
     }
     else
     {
         return(DummyTypeParameter.GetMethodTypeParameter(index));
     }
 }
Esempio n. 5
0
 public ITypeParameter GetClassTypeParameter(int index)
 {
     if (index < ClassTypeParameters?.Count)
     {
         return(ClassTypeParameters[index]);
     }
     else
     {
         return(DummyTypeParameter.GetClassTypeParameter(index));
     }
 }
        public int GetHashCode(IList <IParameter> obj)
        {
            int hashCode = obj.Count;

            unchecked {
                foreach (IParameter p in obj)
                {
                    hashCode *= 27;
                    IType type = DummyTypeParameter.NormalizeMethodTypeParameters(p.Type);
                    hashCode += type.GetHashCode();
                }
            }
            return(hashCode);
        }
Esempio n. 7
0
 public override IType VisitTypeParameter(ITypeParameter type)
 {
     if (type.OwnerType == SymbolKind.Method && ReplaceMethodTypeParametersWithDummy)
     {
         return(DummyTypeParameter.GetMethodTypeParameter(type.Index));
     }
     else if (type.OwnerType == SymbolKind.TypeDefinition && ReplaceClassTypeParametersWithDummy)
     {
         return(DummyTypeParameter.GetClassTypeParameter(type.Index));
     }
     else
     {
         return(base.VisitTypeParameter(type));
     }
 }
Esempio n. 8
0
 public override IType VisitTypeParameter(ITypeParameter type)
 {
     if (type.OwnerType == SymbolKind.Method && ReplaceMethodTypeParametersWithDummy)
     {
         return(DummyTypeParameter.GetMethodTypeParameter(type.Index));
     }
     else if (type.OwnerType == SymbolKind.TypeDefinition && ReplaceClassTypeParametersWithDummy)
     {
         return(DummyTypeParameter.GetClassTypeParameter(type.Index));
     }
     else if (RemoveNullability && type is NullabilityAnnotatedTypeParameter natp)
     {
         return(natp.TypeWithoutAnnotation.AcceptVisitor(this));
     }
     else
     {
         return(base.VisitTypeParameter(type));
     }
 }
        public bool Equals(IList <IParameter> x, IList <IParameter> y)
        {
            if (x == y)
            {
                return(true);
            }
            if (x == null || y == null || x.Count != y.Count)
            {
                return(false);
            }
            for (int i = 0; i < x.Count; i++)
            {
                var a = x[i];
                var b = y[i];
                if (a == null && b == null)
                {
                    continue;
                }
                if (a == null || b == null)
                {
                    return(false);
                }

                // We want to consider the parameter lists "Method<T>(T a)" and "Method<S>(S b)" as equal.
                // However, the parameter types are not considered equal, as T is a different type parameter than S.
                // In order to compare the method signatures, we will normalize all method type parameters.
                IType aType = DummyTypeParameter.NormalizeMethodTypeParameters(a.Type);
                IType bType = DummyTypeParameter.NormalizeMethodTypeParameters(b.Type);

                if (!aType.Equals(bType))
                {
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 10
0
 public IType NormalizeMethodTypeParameters(IType type)
 {
     return(DummyTypeParameter.NormalizeMethodTypeParameters(type));
 }