Esempio n. 1
0
        public static Type GetType(string name, string @namespace = "")
        {
            if (Assemblies == null || !Assemblies.Any())
            {
                Assemblies = GetAllAssemblies();
            }
            List <Type> types = new List <Type>();

            foreach (var asm in Assemblies)
            {
                types.AddRange(asm.GetTypes());
            }
            var typeFound = types.FirstOrDefault(type => type.AssemblyQualifiedName != null &&
                                                 type.AssemblyQualifiedName.Contains(name) &&
                                                 type.AssemblyQualifiedName.Contains(@namespace));

            if (typeFound != null && !string.IsNullOrEmpty(typeFound.AssemblyQualifiedName))
            {
                if (!TypeCache.ContainsKey(typeFound.AssemblyQualifiedName))
                {
                    TypeCache.Add(typeFound.AssemblyQualifiedName, typeFound);
                }
            }
            return(typeFound);
        }
        private static ReadOnlyCollection <Type> GetConcreteTypesCore(Type genericType, LinkList <Binding> bindings)
        {
            Debug.Assert(genericType != null);
            Debug.Assert(bindings != null);

            bool cached  = concreteTypeCache_.ContainsKey(genericType);
            bool unbound = genericType.GetGenericArguments( )
                           .All((a) => !Binding.ContainsArgument(bindings, a));

            // If the type has already been evaluated and there are no interfering bindings, return cached value.
            if (cached && unbound)
            {
                return(concreteTypeCache_[genericType]);
            }


            // Otherwise, get a concrete type for each set of bindings.
            LinkList <Type>   openArguments;
            BindingCollection concreteTypeBindngs = GenericTypeResolver.GetConcreteTypeBindings(genericType, bindings, out openArguments);
            var concreteTypes = concreteTypeBindngs
                                .Transform((argumentBindings) => MakeConcreteType(genericType, openArguments, argumentBindings))
                                .ToReadOnlyCollection( );

            // If there are no interfering bindings, cache the concrete types.
            if (!cached && unbound)
            {
                concreteTypeCache_.TryAdd(genericType, concreteTypes);
                concreteTypes = concreteTypeCache_[genericType];
            }

            return(concreteTypes);
        }
        private static IEnumerable <Type> GetTypes(Assembly assembly)
        {
            if (!types_.ContainsKey(assembly))
            {
                try {
                    types_[assembly] =
                        IsExcludedAssembly(assembly)
                            ? Type.EmptyTypes
                            : GetTypesCore(assembly);
                }
                catch (Exception ex) {
                    if (ex is NotSupportedException && ex.Message.Contains("dynamic"))
                    {
                        // Ignore types from dynamic assemblies.
                        TypeLoader.types_[assembly] = Type.EmptyTypes;
                    }
                    else
                    {
                        // Include assembly that caused the failure.
                        ex.Data[TypeLoaderAssemblyKey] = assembly;
                        throw;
                    }
                }
            }

            return(TypeLoader.types_[assembly]);
        }
Esempio n. 4
0
        /// <summary>
        /// Converts runtime type full name to numeric ID
        /// </summary>
        /// <param name="typeFullName">Runtime type full name</param>
        /// <returns>Object type ID</returns>
        private int GetObjectTypeID(string?typeFullName)
        {
            if (typeFullName == null)
            {
                throw new ArgumentNullException(nameof(typeFullName));
            }

            if (!TypeCache.ContainsKey(typeFullName))
            {
                TypeCache.Add(typeFullName, ++TypeGenID);
                TypeCacheBack.Add(TypeGenID, typeFullName);
            }

            return(TypeCache[typeFullName]);
        }
Esempio n. 5
0
        public virtual void Update(_KEY_TYPE key, _OBJECT_TYPE updated)
        {
            if (ObjectCaching.Enabled)
            {
                try
                {
                    _lock.Lock();

                    if (!_cache.ContainsKey(key))
                    {
                        _cache.Add(key, new CacheEntry <_OBJECT_TYPE>(updated));
                    }
                    else
                    {
                        if (updated is ICopyable <_OBJECT_TYPE> )
                        {
                            ((ICopyable <_OBJECT_TYPE>)_cache[key].CachedObject).CopyFrom(updated);
                            _cache[key].EntryTime = DateTime.UtcNow;
                        }
                        else
                        {
                            _cache[key] = new CacheEntry <_OBJECT_TYPE>(updated);
                        }
                    }

                    if (ObjectCaching.TrackYoungestEntry)
                    {
                        _youngestEntry = _cache[key];
                    }
                }
                finally
                {
                    _lock.Unlock();
                }
            }
        }
Esempio n. 6
0
        public void PrepareDataReader(IDataReader reader)
        {
            if (!TypeCache.ContainsKey(typeof(T)))
            {
                TypeCache.Add(typeof(T), typeof(T).GetProperties().ToList());
            }

            _cache = Enumerable
                     .Range(0, reader.FieldCount)
                     .ToDictionary(reader.GetName, x => x);

            foreach (var notInCache in TypeCache[typeof(T)].Where(x => _cache.All(y => y.Key != x.Name)))
            {
                _cache.Add(notInCache.Name, -1);
            }
        }
Esempio n. 7
0
        private System.Type GetObjectSubtype(System.Type objectType, string discriminator, JObject jObject)
        {
            // Check the type cache.
            if (discriminator != null && TypeCache.ContainsKey(discriminator))
            {
                return(TypeCache[discriminator]);
            }

            // If it's not in the type cache see if it's got a representation.
            // Import it as a GeometricElement.
            if (jObject.TryGetValue("Representation", out JToken representationToken))
            {
                return(typeof(GeometricElement));
            }

            // The default behavior for this converter, as provided by nJSONSchema
            // is to return the base objectType if a derived type can't be found.
            return(objectType);
        }
Esempio n. 8
0
 internal void AssertTypeNotInterned(LLVMTypeRef typeRef)
 {
     Debug.Assert(!TypeCache.ContainsKey(typeRef.Pointer));
 }