Esempio n. 1
0
 public IType ObtainTypeReference(IGeneralTypeUniqueIdentifier typeIdentity, IAssembly originatingAssembly)
 {
     /* *
      * With no assembly as a guide, a guess has to be made.
      * */
     if (typeIdentity.Assembly == null)
     {
         if (this.RuntimeEnvironment.UseCoreLibrary)
         {
             var coreLibraryId  = this.RuntimeEnvironment.CoreLibraryIdentifier;
             var coreLibrary    = this.ObtainAssemblyReference(coreLibraryId);
             var cliCoreLibrary = (ICliAssembly)coreLibrary;
             var type           = cliCoreLibrary.GetType(typeIdentity);
             if (type != null)
             {
                 return(type);
             }
         }
         if (originatingAssembly != null)
         {
             var originatingSearch = originatingAssembly.GetType(typeIdentity);
             if (originatingSearch != null)
             {
                 return(originatingSearch);
             }
             foreach (var assembly in originatingAssembly.References.Values)
             {
                 var test = assembly.GetType(typeIdentity);
                 if (test != null)
                 {
                     return(test);
                 }
             }
         }
     }
     else
     {
         var assembly = this.ObtainAssemblyReference(typeIdentity.Assembly);
         var type     = assembly.GetType(typeIdentity);
         if (type != null)
         {
             return(type);
         }
     }
     throw new TypeLoadException(string.Format("Could not load {0}.", typeIdentity.ToString()));
 }
Esempio n. 2
0
        public IType ObtainTypeReference(IGeneralTypeUniqueIdentifier typeIdentity)
        {
            return(ObtainTypeReference(typeIdentity, null));

            /* *
             * With no assembly as a guide, a guess has to be made.
             * */
            if (typeIdentity.Assembly == null)
            {
                if (this.RuntimeEnvironment.UseCoreLibrary)
                {
                    var coreLibraryId = this.RuntimeEnvironment.CoreLibraryIdentifier;
                    var coreLibrary   = this.ObtainAssemblyReference(coreLibraryId);
                    var type          = coreLibrary.GetType(typeIdentity);
                    if (type != null)
                    {
                        return(type);
                    }
                    foreach (var assembly in this.loadedAssemblies.Values)
                    {
                        if (assembly.UniqueIdentifier == coreLibraryId)
                        {
                            continue;
                        }
                        else if ((type = assembly.GetType(typeIdentity)) != null)
                        {
                            return(type);
                        }
                    }
                }
            }
            else
            {
                var assembly = this.ObtainAssemblyReference(typeIdentity.Assembly);
                var type     = assembly.GetType(typeIdentity);
                if (type != null)
                {
                    return(type);
                }
            }
            throw new TypeLoadException(string.Format("Could not load {0}.", typeIdentity.ToString()));
        }