示例#1
0
        /// <summary>
        /// As a fallback, so if the type does exist in any assembly. This would happen if a new type was added
        /// that was not in the hardcoded list of types.
        /// This code is not accurate because:
        /// 1. We dont deal with generic types (TypeCollision).
        /// 2. Previous calls to GetCustomMemberNames (eg. "from foo import *" in Python) would not have included this type.
        /// 3. This does not deal with new namespaces added to the assembly
        /// </summary>
        private MemberTracker CheckForUnlistedType(string nameString)
        {
            Assert.NotNull(nameString);

            string fullTypeName = GetFullChildName(nameString);

            foreach (Assembly assem in _packageAssemblies)
            {
                Type type = assem.GetType(fullTypeName);
                if (type == null || type.IsNested())
                {
                    continue;
                }

                bool publishType = type.IsPublic() || _topPackage.DomainManager.Configuration.PrivateBinding;
                if (!publishType)
                {
                    continue;
                }

                // We dont use TypeCollision.UpdateTypeEntity here because we do not handle generic type names
                return(TypeTracker.GetTypeTracker(type));
            }

            return(null);
        }
示例#2
0
文件: TypeGroup.cs 项目: xia7410/dlr
 public TypeTracker GetTypeForArity(int arity)
 {
     if (!_typesByArity.TryGetValue(arity, out Type typeWithMatchingArity))
     {
         return(null);
     }
     return(TypeTracker.GetTypeTracker(typeWithMatchingArity));
 }
示例#3
0
            internal MemberTracker UpdateTypeEntity(TypeTracker existingTypeEntity, string normalizedTypeName)
            {
                Debug.Assert(normalizedTypeName.IndexOf('.') == -1); // This is the simple name, not the full name
                Debug.Assert(ReflectionUtils.GetNormalizedTypeName(normalizedTypeName) == normalizedTypeName);

                // Look for a non-generic type
                if (_simpleTypeNames.Contains(normalizedTypeName))
                {
                    Type newType = LoadType(_assembly, GetFullChildName(normalizedTypeName));
                    if (newType != null)
                    {
                        existingTypeEntity = TypeGroup.UpdateTypeEntity(existingTypeEntity, TypeTracker.GetTypeTracker(newType));
                    }
                }

                // Look for generic types
                if (_genericTypeNames.ContainsKey(normalizedTypeName))
                {
                    List <string> actualNames = _genericTypeNames[normalizedTypeName];
                    foreach (string actualName in actualNames)
                    {
                        Type newType = LoadType(_assembly, GetFullChildName(actualName));
                        if (newType != null)
                        {
                            existingTypeEntity = TypeGroup.UpdateTypeEntity(existingTypeEntity, TypeTracker.GetTypeTracker(newType));
                        }
                    }
                }

                return(existingTypeEntity);
            }
示例#4
0
        internal void AddTypeName(string typeName, Assembly assem)
        {
            // lock is held when this is called
            Assert.NotNull(typeName, assem);
            Debug.Assert(typeName.IndexOf('.') == -1); // This is the simple name, not the full name

            if (!_typeNames.ContainsKey(assem))
            {
                _typeNames[assem] = new TypeNames(assem, _fullName);
            }
            _typeNames[assem].AddTypeName(typeName);

            string normalizedTypeName = ReflectionUtils.GetNormalizedTypeName(typeName);

            if (_dict.ContainsKey(normalizedTypeName))
            {
                // A similarly named type, namespace, or module already exists.
                Type newType = LoadType(assem, GetFullChildName(typeName));

                if (newType != null)
                {
                    object      existingValue      = _dict[normalizedTypeName];
                    TypeTracker existingTypeEntity = existingValue as TypeTracker;
                    if (existingTypeEntity == null)
                    {
                        // Replace the existing namespace or module with the new type
                        Debug.Assert(existingValue is NamespaceTracker);
                        _dict[normalizedTypeName] = MemberTracker.FromMemberInfo(newType.GetTypeInfo());
                    }
                    else
                    {
                        // Unify the new type with the existing type
                        _dict[normalizedTypeName] = TypeGroup.UpdateTypeEntity(existingTypeEntity, TypeTracker.GetTypeTracker(newType));
                    }
                }
            }
        }