Exemplo n.º 1
0
        public static Type FindType <TLoadType>(AssemblyInfo assemblyInfo, string debugDefault = "")
        {
            Type protocol = null;

            var assemblyFile = FileSystem.Current.GetFileFromPathAsync(assemblyInfo.FilePath).Result;

            if (assemblyFile != null)
            {
                using (var stream = assemblyFile.OpenAsync(FileAccess.Read).Result)
                {
                    var asm = AppDomainWrapper.LoadAssembly(stream.ReadFully());
                    if (asm != null)
                    {
                        protocol = asm.DefinedTypes.Single(typeInfo => typeInfo.IsSubclassOf(typeof(TLoadType))).AsType();
                    }
                }
            }

            /*
             * var assemblyFolder = FileSystemWrapper.AssemblyFolder;
             * if (assemblyFolder != null && assemblyFolder.CheckExistsAsync(assemblyInfo.FileName).Result == ExistenceCheckResult.FileExists)
             * {
             *  using (var stream = assemblyFolder.GetFileAsync(assemblyInfo.FileName).Result.OpenAsync(FileAccess.Read).Result)
             *  {
             *      var asm = AppDomainWrapper.LoadAssembly(stream.ReadFully());
             *      if (asm != null)
             *          protocol = asm.DefinedTypes.Single(typeInfo => typeInfo.IsSubclassOf(typeof (TLoadType))).AsType();
             *  }
             * }
             */

            #region Debug
            if (protocol == null)
            {
                var asm = Assembly.Load(new AssemblyName(debugDefault));
                if (asm != null)
                {
                    protocol = asm.DefinedTypes.Single(typeInfo => typeInfo.IsSubclassOf(typeof(TLoadType))).AsType();
                }
            }
            #endregion Debug


            return(protocol);
        }