Beispiel #1
0
 static ITypeParameter GetTypeParameter(ref ITypeParameter[] typeParameters, SymbolKind symbolKind, int index)
 {
     ITypeParameter[] tps = typeParameters;
     while (index >= tps.Length)
     {
         // We don't have a normal type parameter for this index, so we need to extend our array.
         // Because the array can be used concurrently from multiple threads, we have to use
         // Interlocked.CompareExchange.
         ITypeParameter[] newTps = new ITypeParameter[index + 1];
         tps.CopyTo(newTps, 0);
         for (int i = tps.Length; i < newTps.Length; i++)
         {
             newTps[i] = new DummyTypeParameter(symbolKind, i);
         }
         ITypeParameter[] oldTps = Interlocked.CompareExchange(ref typeParameters, newTps, tps);
         if (oldTps == tps)
         {
             // exchange successful
             tps = newTps;
         }
         else
         {
             // exchange not successful
             tps = oldTps;
         }
     }
     return(tps[index]);
 }
Beispiel #2
0
 public IType Resolve(ITypeResolveContext context)
 {
     if (ownerType == SymbolKind.Method)
     {
         IMethod method = context.CurrentMember as IMethod;
         if (method != null && index < method.TypeParameters.Count)
         {
             return(method.TypeParameters[index]);
         }
         return(DummyTypeParameter.GetMethodTypeParameter(index));
     }
     else if (ownerType == SymbolKind.TypeDefinition)
     {
         ITypeDefinition typeDef = context.CurrentTypeDefinition;
         if (typeDef != null && index < typeDef.TypeParameters.Count)
         {
             return(typeDef.TypeParameters[index]);
         }
         return(DummyTypeParameter.GetClassTypeParameter(index));
     }
     else
     {
         return(SpecialType.UnknownType);
     }
 }
Beispiel #3
0
        public IMember Resolve(ITypeResolveContext context)
        {
            IType type = typeReference.Resolve(context);
            IEnumerable <IMember> members;

            if (symbolKind == SymbolKind.Accessor)
            {
                members = type.GetAccessors(
                    m => m.Name == name && !m.IsExplicitInterfaceImplementation,
                    GetMemberOptions.IgnoreInheritedMembers);
            }
            else if (symbolKind == SymbolKind.Method)
            {
                members = type.GetMethods(
                    m => m.Name == name && m.SymbolKind == SymbolKind.Method &&
                    m.TypeParameters.Count == typeParameterCount && !m.IsExplicitInterfaceImplementation,
                    GetMemberOptions.IgnoreInheritedMembers);
            }
            else
            {
                members = type.GetMembers(
                    m => m.Name == name && m.SymbolKind == symbolKind && !m.IsExplicitInterfaceImplementation,
                    GetMemberOptions.IgnoreInheritedMembers);
            }
            var resolvedParameterTypes = parameterTypes.Resolve(context);

            foreach (IMember member in members)
            {
                IParameterizedMember parameterizedMember = member as IParameterizedMember;
                if (parameterizedMember == null)
                {
                    if (parameterTypes.Count == 0)
                    {
                        return(member);
                    }
                }
                else if (parameterTypes.Count == parameterizedMember.Parameters.Count)
                {
                    bool signatureMatches = true;
                    for (int i = 0; i < parameterTypes.Count; i++)
                    {
                        IType type1 = DummyTypeParameter.NormalizeAllTypeParameters(resolvedParameterTypes[i]);
                        IType type2 = DummyTypeParameter.NormalizeAllTypeParameters(parameterizedMember.Parameters[i].Type);
                        if (!type1.Equals(type2))
                        {
                            signatureMatches = false;
                            break;
                        }
                    }
                    if (signatureMatches)
                    {
                        return(member);
                    }
                }
            }
            return(null);
        }
 public override IType VisitTypeParameter(ITypeParameter type)
 {
     if (type.OwnerType == SymbolKind.TypeDefinition)
     {
         return(DummyTypeParameter.GetClassTypeParameter(type.Index));
     }
     else
     {
         return(base.VisitTypeParameter(type));
     }
 }
 public override IType VisitTypeParameter(ITypeParameter type)
 {
     if (type.OwnerType == SymbolKind.Method)
     {
         return(DummyTypeParameter.GetMethodTypeParameter(type.Index));
     }
     else
     {
         return(base.VisitTypeParameter(type));
     }
 }