Example #1
0
        public static Type GetTypeInAnyAssembly(string typeName, string namespaceIfAmbiguous = null)
        {
            TypeCacheKey key   = new TypeCacheKey(typeName, namespaceIfAmbiguous);
            Type         value = null;

            if (!typeCache.TryGetValue(key, out value))
            {
                value = GetTypeInAnyAssemblyInt(typeName, namespaceIfAmbiguous);
                typeCache.Add(key, value);
            }
            return(value);
        }
Example #2
0
        public static SerializableTypeCache GetSerializableTypeCacheFor(string writtenName, string preferredNamespace)
        {
            TypeCacheKey cacheKey  = new TypeCacheKey(writtenName, preferredNamespace);
            Type         foundType = null;

            if (!_serializableTypeCache.TryGetValue(cacheKey, out foundType))
            {
                bool dontDoNamespaceCheck = string.IsNullOrEmpty(preferredNamespace);
                LazyAllTypesInit();

                int len = allTypes.Length;
                for (int i = 0; i < len; i++)
                {
                    Type t = allTypes[i];
                    if (t.Name.Equals(writtenName) && (dontDoNamespaceCheck || t.Namespace.Equals(preferredNamespace)))
                    {
                        foundType = t;
                        break;
                    }
                }

                if (foundType == null && !dontDoNamespaceCheck)
                {
                    var t = GetSerializableTypeCacheFor(writtenName, null);
                    if (t != null)
                    {
                        return(t);
                    }
                }

                _serializableTypeCache.Add(cacheKey, foundType);
            }

            if (!ReferenceEquals(foundType, null))
            {
                return(GetSerializableTypeCacheFor(foundType));
            }

            return(null);
        }