C# IOException.GetType的代码示例

通过代码示例来学习C# IOException.GetType方法

通过代码示例来学习编程是非常高效的。
1. 代码示例提供了一个具体而直观的学习环境,使初学者能够立即看到编程概念和语法的实际应用。
2. 通过分析和模仿现有的代码实例,初学者可以更好地理解编程逻辑和算法的工作原理。
3. 代码实例往往涵盖了多种编程技巧和最佳实践,通过学习和模仿这些实例,学习者可以逐步掌握如何编写高效、可读性强和可维护的代码。这对于初学者来说,是一种快速提升编程水平的有效途径。


IOException.GetType是C#的System.IO命名空间下中的一个方法, 小编为大家找了一些网络大拿们常见的代码示例,源码中的IOException.GetType() 已经帮大家高亮显示了,大家可以重点学习IOException.GetType() 方法的写法,从而快速掌握该方法的应用。

IOException.GetType的代码示例1 - TryLoadFromDisk()

    using System.IO;

        /// An optional callback to be run as soon as the fileLock is taken
        protected bool TryLoadFromDisk(
            TryParseAdd tryParseAdd,
            TryParseRemove tryParseRemove,
            Action add,
            out string error,
            Action synchronizedAction = null)
        {
            lock (this.fileLock)
            {
                try
                {
                    if (synchronizedAction != null)
                    {
                        synchronizedAction();
                    }

                    this.fileSystem.CreateDirectory(this.dataDirectoryPath);

                    this.OpenOrCreateDataFile(retryUntilSuccess: false);

                    if (this.collectionAppendsDirectlyToFile)
                    {
                        this.RemoveLastEntryIfInvalid();
                    }

                    long lineCount = 0;

                    this.dataFileHandle.Seek(0, SeekOrigin.Begin);
                    StreamReader reader = new StreamReader(this.dataFileHandle);
                    Dictionary parsedEntries = new Dictionary();
                    while (!reader.EndOfStream)
                    {
                        lineCount++;

                        // StreamReader strips the trailing /r/n
                        string line = reader.ReadLine();
                        if (line.StartsWith(RemoveEntryPrefix))
                        {
                            TKey key;
                            if (!tryParseRemove(line.Substring(RemoveEntryPrefix.Length), out key, out error))
                            {
                                error = string.Format("{0} is corrupt on line {1}: {2}", this.GetType().Name, lineCount, error);
                                return false;
                            }

                            parsedEntries.Remove(key);
                        }
                        else if (line.StartsWith(AddEntryPrefix))
                        {
                            TKey key;
                            TValue value;
                            if (!tryParseAdd(line.Substring(AddEntryPrefix.Length), out key, out value, out error))
                            {
                                error = string.Format("{0} is corrupt on line {1}: {2}", this.GetType().Name, lineCount, error);
                                return false;
                            }

                            parsedEntries[key] = value;
                        }
                        else
                        {
                            error = string.Format("{0} is corrupt on line {1}: Invalid Prefix '{2}'", this.GetType().Name, lineCount, line[0]);
                            return false;
                        }
                    }

                    foreach (KeyValuePair kvp in parsedEntries)
                    {
                        add(kvp.Key, kvp.Value);
                    }

                    if (!this.collectionAppendsDirectlyToFile)
                    {
                        this.CloseDataFile();
                    }
                }
                catch (IOException ex)
                {
                    error = ex.ToString();
                    this.CloseDataFile();
                    return false;
                }
                catch (Exception e)
                {
                    this.CloseDataFile();
                    throw new FileBasedCollectionException(e);
                }

                error = null;
                return true;
            }
        }
    

开发者ID:microsoft,项目名称:VFSForGit,代码行数:95,代码来源:FileBasedCollection.cs

在TryLoadFromDisk()方法中,IOException的代码示例类中的GetType的代码示例方法一共出现了3次, 见黄色背景高亮显示的地方,欢迎大家点赞

IOException.GetType的代码示例2 - LoadConfig()

    using System.IO;

        public void LoadConfig(string configDir)
        {
            XmlSerializer xml = new XmlSerializer(ConfigData.GetType());

            FileInfo configFile = new FileInfo(configDir + "\\" + "sftpfilesystem.cfg");

            if (!configFile.Exists)
            {
                return;
            }

            FileStream fs = null;

            try
            {
                fs = configFile.OpenRead();

                ConfigData = (ConfigData) xml.Deserialize(fs);
            }
            catch (IOException e)
            {
                _logger.LogError(e.Message);
            }
            finally
            {
                fs?.Flush();
                fs?.Close();
                fs?.Dispose();
            }
        }
    

开发者ID:zarunbal,项目名称:LogExpert,代码行数:32,代码来源:SftpFileSystem.cs

在LoadConfig()方法中,IOException的代码示例类中的GetType的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

IOException.GetType的代码示例3 - CloseInputStream()

    using System.IO;
        /**
         * @param stream the stream to be Closed
         * @param success false if an exception is currently being thrown in the calling method
         */
        private void CloseInputStream(Stream stream, bool success) {
            
            if(stream is MemoryStream) {
                String msg = "POIFS is closing the supplied input stream of type (" 
                        + stream.GetType().Name + ") which supports mark/reset.  "
                        + "This will be a problem for the caller if the stream will still be used.  "
                        + "If that is the case the caller should wrap the input stream to avoid this Close logic.  "
                        + "This warning is only temporary and will not be present in future versions of POI.";
                //_logger.Log(POILogger.WARN, msg);
            }
            try {
                stream.Close();
            } catch (IOException) {
                if(success) {
                    throw;
                }
                // else not success? Try block did not complete normally 
                // just print stack trace and leave original ex to be thrown
                //e.StackTrace;
            }
        }
    

开发者ID:dotnetcore,项目名称:NPOI,代码行数:26,代码来源:POIFSFileSystem.cs

在CloseInputStream()方法中,IOException的代码示例类中的GetType的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

IOException.GetType的代码示例4 - WriteOutAndReadBack()

    using System.IO;
        public static IWorkbook WriteOutAndReadBack(IWorkbook wb)
        {
            IWorkbook result;
            try
            {
                using (MemoryStream baos = new MemoryStream(8192))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    wb.Write(baos);
                    sw.Stop();
                    Debug.WriteLine("XSSFWorkbook write time: " + sw.ElapsedMilliseconds + "ms");
                    using (Stream is1 = new MemoryStream(baos.ToArray()))
                    {
                        if (wb is HSSFWorkbook)
                        {
                            result = new HSSFWorkbook(is1);
                        }
                        else if (wb is XSSFWorkbook)
                        {
                            Stopwatch sw2 = new Stopwatch();
                            sw2.Start();
                            result = new XSSFWorkbook(is1);
                            sw2.Stop();
                            Debug.WriteLine("XSSFWorkbook parse time: " + sw2.ElapsedMilliseconds + "ms");
                        }
                        else
                        {
                            throw new RuntimeException("Unexpected workbook type ("
                                    + wb.GetType().Name + ")");
                        }
                    }
                }
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            return result;
        }
    

开发者ID:dotnetcore,项目名称:NPOI,代码行数:41,代码来源:XSSFTestDataSamples.cs

在WriteOutAndReadBack()方法中,IOException的代码示例类中的GetType的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

IOException.GetType的代码示例5 - Marshall()

    using System.IO;

        /**
         * Save the specified part.
         *
         * @throws OpenXml4NetException
         *             Throws if an internal exception is thrown.
         */
        public bool Marshall(PackagePart part, Stream os)
        {
            if (!(os is ZipOutputStream))
            {
                logger.Log(POILogger.ERROR,"Unexpected class " + os.GetType().Name);
                throw new OpenXml4NetException("ZipOutputStream expected !");
                // Normally should happen only in developement phase, so just throw
                // exception
            }

            ZipOutputStream zos = (ZipOutputStream)os;
            string name = ZipHelper
                    .GetZipItemNameFromOPCName(part.PartName.URI
                            .OriginalString);
            ZipEntry partEntry = new ZipEntry(name);
            try
            {
                // Create next zip entry
                zos.PutNextEntry(partEntry);

                // Saving data in the ZIP file
                Stream ins = part.GetInputStream();
                byte[] buff = new byte[ZipHelper.READ_WRITE_FILE_BUFFER_SIZE];
                int totalRead = 0;
                while (true)
                {
                    int resultRead = ins.Read(buff, 0, buff.Length);
                    if (resultRead == 0)
                    {
                        // End of file reached
                        break;
                    }
                    zos.Write(buff, 0, resultRead);
                    totalRead += resultRead;
                }
                zos.CloseEntry();
            }
            catch (IOException ioe)
            {
                logger.Log(POILogger.ERROR, "Cannot write: " + part.PartName + ": in ZIP", ioe);
                return false;
            }

            // Saving relationship part
            if (part.HasRelationships)
            {
                PackagePartName relationshipPartName = PackagingUriHelper
                        .GetRelationshipPartName(part.PartName);

                MarshallRelationshipPart(part.Relationships,
                        relationshipPartName, zos);

            }
            return true;
        }
    

开发者ID:dotnetcore,项目名称:NPOI,代码行数:63,代码来源:ZipPartMarshaller.cs

在Marshall()方法中,IOException的代码示例类中的GetType的代码示例方法一共出现了1次, 见黄色背景高亮显示的地方,欢迎大家点赞

本文中的IOException.GetType方法示例由csref.cn整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。